Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Wed, 01 Jun 2011 09:19:01 -0500 Date: Wed, 01 Jun 2011 07:18:59 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Making one or more threads wait for another to produce a value or fail References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 38 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-dNKrerNa7Ix31VHonrPPSRr2QPhsDqVdQoCQXEUVCaKI6BarotpMxL/Uw5a07xlCqH6UC5Pw6fBx9jF!QciHz+887SffNXTkOhVU8dpA108Ixp+u5sdBGpOJUspuQ8WhBTkJiLfC0JUi0WDw/6LG+sEz4hHy!sFeKonc8QBmS9LrEgUgNl4vnfOjO3+orcMdBJE8QGLE= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3496 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4853 On 5/31/11 9:37 PM, Patricia Shanahan wrote: > On 5/31/2011 8:45 PM, Peter Duniho wrote: > .... >> Spurious wakeup, yes (why people continue to tolerate that in Java, I >> have no idea…plenty of other APIs with concurrency support don't have >> that trouble). > > I don't continue to tolerate spurious wake-ups in Java. My view of wait > and notify is that they are low level primitives that I used as long as > they were all we had. Why not use e.g. CountDownLatch? That's certainly one way to look at it. But you are still "tolerating" spurious wake-ups in the sense in which I wrote that. Why should the language _force_ you to avoid what would otherwise be perfectly good program statements? In a language like Java, there really shouldn't be any such thing as "low level primitives", except those that are still useful and easy to use. The entire programmer-available surface should be usable as-is. Yes, it's great when the libraries offer an abstraction that more closely fits ones needs, but for there to be statements in Java that pretty much just _always_ need working-around through the use of some helper class doesn't make sense to me. Spurious wake-ups offer no benefit to the user (i.e. the programmer) and are a symptom of implementation detail bleeding through into the higher-level language. It's a strange anomaly in what is otherwise normally a very helpful and relatively simple (in a good way) high-level language. The .NET equivalent (for example) has well-defined and reliable behavior: if your thread wakes up from waiting, you know it was on purpose. And guess what? Sure, sometimes it's nice to wrap the "low level primitives" in a helper class (or use a pre-existing one), but a lot of the time it's just as easy to go ahead and use those "low level primitives", because they do what you _want_ them to do. Pete