[concurrency-interest] Propagation of signals tonon-interrupted thread

Martin Buchholz martinrb at google.com
Fri Nov 11 13:27:00 EST 2011

(Heinz: apologies for the thread hijack)

On Fri, Nov 11, 2011 at 09:00, David M. Lloyd <david.lloyd at redhat.com>wrote:

> Absolutely.  Spurious wakeups are an indelible part of the park()/unpark()
> contract, and in fact can make coding certain things possible or at least
> much easier.  Never, ever, ever, ever assume that they can't happen, no
> matter what you hear from anyone.
> park/unpark can and do wake up spuriously.

Object.wait is documented as being able to wake up spuriously (not sure
whether it happens in practice)

I'm only trying to change the spec for AQS-based conditions, since AQS is
carefully written to exclude spurious wakeups.
Arguably, Condition *requires* us to document the additional guarantee:

 * <p>A {@code Condition} implementation can provide behavior and semantics
 * that is
 * different from that of the {@code Object} monitor methods, such as
 * guaranteed ordering for notifications, or not requiring a lock to be held
 * when performing notifications.
 * If an implementation provides such specialized semantics then the
 * implementation must document those semantics.

We can add disclaimers:

--- java/util/concurrent/locks/ReentrantLock.java 9 Jun 2011 07:48:44 -0000
+++ java/util/concurrent/locks/ReentrantLock.java 11 Nov 2011 18:16:05 -0000
@@ -467,6 +467,13 @@
      * but for <em>fair</em> locks favors those threads that have been
      * waiting the longest.
+     * <li>None of the condition {@linkplain Condition#await() waiting}
+     * methods ever return due to a "<em>spurious wakeup</em>".
+     * However, as explained in the {@link Condition} documentation,
+     * this has little practical impact on most application programs as
+     * a {@code Condition} should generally be waited upon in a loop,
+     * testing the state predicate that is being waited for.
+     *
      * </ul>
      * @return the Condition object
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20111111/76b75b32/attachment.html>

More information about the Concurrency-interest mailing list