From: "Trenton D. Adams" <tadams@theone.dnsalias.com>
To: "'eCos Disuss'" <ecos-discuss@sourceware.cygnus.com>
Subject: [ECOS] condition variables and mutexes
Date: Thu, 09 Aug 2001 14:08:00 -0000 [thread overview]
Message-ID: <101701c12117$717741d0$090110ac@TRENT> (raw)
Are the mutexes used with condition variables customarily used for
synchronization with other consumer threads only, or does the producer
thread use the mutexes as well?
I would imagine that the producer thread would generally not use the
mutex associated with a condition variable. I would think that if a
mutex is needed, I should probably create a separate one for my use,
right?
Do I even care about the mutex associated with the condition variable if
I only have one consumer, and one producer?
Here's my situation in particular.
I've created a circular buffer that will hold three times the amount of
data required for each cycle. Cycles usually occur once every second.
I've created three condition/mutex variable pairs for each of the three
slots in the circular buffer.
Producer thread
- fill the first slot of the buffer with the data, and signal the
consumer thread (condition 1)
- fill the second slot of the buffer with the data, and signal the
consumer thread (condition 2)
- fill the third slot of the buffer with the data, and signal the
consumer thread (condition 3)
Consumer thread
loop indefinately
- wait for signal 1
- COPY data to another buffer
- do something with data
- wait for signal 2
- COPY data to another buffer
- do something with data
- wait for signal 3
- COPY data to another buffer
- do something with data
I need a way of making sure that the head pointer of the circular buffer
doesn't change to point to the next slot before the consumer thread has
copied it. I was thinking of using a mutex for this purpose.
Trenton D. Adams
Extreme Engineering
#17, 6025 - 12 St. SE
Calgary, Alberta, Canada
T2H 2K1
Phone: 403 640 9494 ext-208
Fax: 403 640 9599
http://www.extremeeng.com
next reply other threads:[~2001-08-09 14:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-09 14:08 Trenton D. Adams [this message]
2001-08-10 3:00 ` Nick Garnett
2001-08-10 7:37 ` Trenton D. Adams
2001-08-10 7:52 ` Trenton D. Adams
2001-08-10 8:06 ` Nick Garnett
2001-08-10 8:39 ` Robin Farine
2001-08-10 8:50 ` Robin Farine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='101701c12117$717741d0$090110ac@TRENT' \
--to=tadams@theone.dnsalias.com \
--cc=ecos-discuss@sourceware.cygnus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).