[concurrency-interest] Propagation of signals to non-interruptedthread

David Holmes davidcholmes at aapt.net.au
Thu Nov 10 17:50:52 EST 2011


Pre-Java 5 the semantics of how interrupts and notifications interacted was
under-specified and at one time a thread that received a notification could
then see it was also interrupted and throw the IE, causing the notification
to be lost. We fixed that in the spec in Java 5 (and in the VM) but the
defensive coding construct of sending a signal/notify upon getting IE
remained in the code. We eventually removed that in the Java 7 time-frame.

David

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Dr Heinz
> M. Kabutz
> Sent: Thursday, 10 November 2011 11:15 PM
> To: concurrency-interest at cs.oswego.edu
> Subject: [concurrency-interest] Propagation of signals to
> non-interruptedthread
>
>
> In Java 6, the ArrayBlockingQueue used this construct for the
> take() method:
>
>     public E take() throws InterruptedException {
>         final ReentrantLock lock = this.lock;
>         lock.lockInterruptibly();
>         try {
>             try {
>                 while (count == 0)
>                     notEmpty.await();
>             } catch (InterruptedException ie) {
>                 notEmpty.signal(); // propagate to non-interrupted thread
>                 throw ie;
>             }
>             E x = extract();
>             return x;
>         } finally {
>             lock.unlock();
>         }
>     }
>
> In other words, it would /always/ send a signal on interrupt, even if it
> had not received one.
>
> In Java 7, this was taken away, so we now have:
>
>     public E take() throws InterruptedException {
>         final ReentrantLock lock = this.lock;
>         lock.lockInterruptibly();
>         try {
>             while (count == 0)
>                 notEmpty.await();
>             return extract();
>         } finally {
>             lock.unlock();
>         }
>     }
>
> However, I could not find substantial differences between the await()
> methods of Java 6 and 7.  Does this mean that propagating of the signal
> was not necessary in Java 6 either?  According to Doug Lea's book
> section 3.2.4.2, it is necessary with wait/notify to propagate the
> signal if you get interrupted.  However, it looks like Condition.await()
> is coded to cater for this eventuality anyway.
>
> Regards
>
> Heinz
> --
> Dr Heinz M. Kabutz (PhD CompSci)
> Author of "The Java(tm) Specialists' Newsletter"
> Sun Java Champion
> IEEE Certified Software Development Professional
> http://www.javaspecialists.eu
> Tel: +30 69 72 850 460
> Skype: kabutz
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



More information about the Concurrency-interest mailing list