X-Received: by 10.68.226.168 with SMTP id rt8mr3129762pbc.8.1356321762873; Sun, 23 Dec 2012 20:02:42 -0800 (PST) Received: by 10.50.42.194 with SMTP id q2mr7539974igl.11.1356321762834; Sun, 23 Dec 2012 20:02:42 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!newsfeed.news.ucla.edu!usenet.stanford.edu!f6no14678232pbd.1!news-out.google.com!s9ni56359pbb.0!nntp.google.com!kr7no8059466pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.programming.threads Date: Sun, 23 Dec 2012 20:02:42 -0800 (PST) In-Reply-To: <0.a47ead5e11f16b983c51.20121221144029GMT.87a9t78o4i.fsf@bsb.me.uk> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=116.252.156.45; posting-account=0gvzRgoAAAD7Lpquvmb26pYmSD9lG7LB NNTP-Posting-Host: 116.252.156.45 References: <0.a47ead5e11f16b983c51.20121221144029GMT.87a9t78o4i.fsf@bsb.me.uk> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Have you ever seen real world lost wake-up problems? From: Tian Tan Injection-Date: Mon, 24 Dec 2012 04:02:42 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.programming.threads:1268 > And what CV implementation allows one to specify the thread that should > > be woken up? If there can be only one waiting thread, there's nothing > > lost by using the conventional signalling mechanism, and if there can be > > many waiting threads, targeting the notification is almost certainly > > going to cause problems. > What does it mean? Why multi-waiting-threads is going to cause problems? > You might also lack some knowledge as well. Obviously I can't tell, but > > the example above looks so wrong it doesn't seem likely to be common > > patter for a bug. > You're right, it's too naive. CV shouldn't be used like that. > It's not clear what the bug is you are talking about. Anyway, I lack the > > experience to estimate how common any particular synchronisation bug is. > The bug which I'm talking about can be concluded like this: http://docs.oracle.com/cd/E19253-01/816-5137/sync-30/index.html > > Yes. You just need to use CVs correctly -- associate them with a real > > condition and a mutex (or lock) and test the condition in a loop with > > the correct locking: > > > > mutex.lock() > > while (the condition I need is not true) > > cv.wait(mutex); > > mutex.unlock(); > > If you find examples of incorrectly used condition variables, that would > > have some value (you could submit bug reports for example) but if it is > > valuable enough to spend time looking for them, I can't say. > It's helpful, thank you Ben. -- TT