Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #188
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news.mixmin.net!news2.arglkargh.de!news.karotte.org!uucp.gnuu.de!feed.cnntp.org!news.cnntp.org!not-for-mail |
|---|---|
| From | Anthony Williams <anthony.ajw@gmail.com> |
| Newsgroups | comp.programming.threads |
| Subject | Re: cond signal wait |
| References | <bff468ff-45d7-4e18-8ff5-95238eb94585@c1g2000yqe.googlegroups.com> <87aaebte7o.fsf@justsoftwaresolutions.co.uk> <98cd47de-73d9-48e9-ac18-cc01cac1bb48@z7g2000prh.googlegroups.com> |
| Date | Wed, 25 May 2011 15:57:25 +0100 |
| Message-ID | <87lixubzfu.fsf@justsoftwaresolutions.co.uk> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
| Cancel-Lock | sha1:skdvVDS6XPMDBGjGdU/d7Sk65ks= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Lines | 51 |
| Organization | CNNTP |
| NNTP-Posting-Host | 0bcb2622.read.cnntp.org |
| X-Trace | DXC=`hkKkbIbFRTIF90FU:O7kPWoT\PAgXa?Q80L@He?SN;Y31?8ZVJ3gMUGj6PdB418W^OI:PE^HAYMU<l<CH0hVULR |
| X-Complaints-To | abuse@cnntp.org |
| Xref | x330-a1.tempe.blueboxinc.net comp.programming.threads:188 |
Show key headers only | View raw
p6 c6d6 <p6c6d6@gmail.com> writes: > On May 25, 12:46 pm, Anthony Williams <anthony....@gmail.com> wrote: >> p6 c6d6 <p6c...@gmail.com> writes: >> > what happens if a thread does a condition signal for a thread that has >> > not yet done >> > condition wait. is this not legitimate scenario, according to my >> > limited experience in >> > thread programming, i feel it is always possible. am i missing >> > anything.or are there any >> > ways to deterministically signal and wait. please shed some light. >> >> If you signal a condition variable with no threads blocked in a waiting >> function then the signal has no effect. >> >> Anthony >> -- >> Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ >> just::thread C++0x thread library http://www.stdthread.co.uk >> Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk >> 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976 > > that is fine. but what if the thread which is suppose to recv the > signal > waits after the signal was delivered. doesn't it wait forever. Yes, if there is no-one waiting when the condvar was signalled, then the signal is ignored, and if the condvar is not subsequently signalled then any subsequent waiting threads will block forever, unless they use a timeout. > let's assume a reader writer scenario. the writer writes one byte and > waits for the reader to read and signal the writer. now if the writer > writes some data and does a cond signal. during this time the reader > was busy doing something else or didn't get a chance to run at > all. now the reader waits on condition, and the signal was already > lost. both reader and writer wait forever. isn't this a valid > scenario. Yes. However, if you hold the mutex that is associated with the cond var whilst signalling, then you can avoid this: if the signalling thread has the mutex then either (a) the waiting thread hasn't yet acquired the mutex to check if the data is ready, or (b) the waiting thread is blocked in the wait on the condvar. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
cond signal wait p6 c6d6 <p6c6d6@gmail.com> - 2011-05-24 18:56 -0700
Re: cond signal wait Anthony Williams <anthony.ajw@gmail.com> - 2011-05-25 08:46 +0100
Re: cond signal wait p6 c6d6 <p6c6d6@gmail.com> - 2011-05-25 05:44 -0700
Re: cond signal wait Anthony Williams <anthony.ajw@gmail.com> - 2011-05-25 15:57 +0100
Re: cond signal wait p6 c6d6 <p6c6d6@gmail.com> - 2011-05-25 08:34 -0700
Re: cond signal wait Anthony Williams <anthony.ajw@gmail.com> - 2011-05-25 16:53 +0100
Re: cond signal wait Alexander Terekhov <terekhov@web.de> - 2011-05-25 19:16 +0200
Re: cond signal wait David Schwartz <davids@webmaster.com> - 2011-05-26 09:51 -0700
Re: cond signal wait Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-26 14:48 -0700
Re: cond signal wait David Schwartz <davids@webmaster.com> - 2011-05-26 23:20 -0700
Re: cond signal wait Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-27 14:50 -0700
Re: cond signal wait David Schwartz <davids@webmaster.com> - 2011-05-27 15:15 -0700
Re: cond signal wait Alexander Terekhov <terekhov@web.de> - 2011-05-28 15:48 +0200
Re: cond signal wait Alexander Terekhov <terekhov@web.de> - 2011-05-27 16:01 +0200
Re: cond signal wait David Schwartz <davids@webmaster.com> - 2011-05-27 12:34 -0700
Re: cond signal wait Alexander Terekhov <terekhov@web.de> - 2011-05-28 14:24 +0200
Re: cond signal wait David Schwartz <davids@webmaster.com> - 2011-05-29 01:33 -0700
Re: cond signal wait Alexander Terekhov <terekhov@web.de> - 2011-05-31 15:32 +0200
Re: cond signal wait David Schwartz <davids@webmaster.com> - 2011-05-31 14:07 -0700
csiph-web