Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Re: In Mutex.aq...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 52654 of 55513
Post > Topic >>

Re: In Mutex.aquire why do we need to throw InterruptedException

by Szabolcs Ferenczi <szabolcs.ferenczi@[EMAIL PROTECTED] > May 12, 2008 at 08:49 AM

On May 12, 2:51=A0am, Logan Shaw <lshaw-use...@[EMAIL PROTECTED]
> wrote:
> Arne Vajh=F8j wrote:
> > puzzlecracker wrote:
> >> It is a copy and paste from Doug Lea's Mutex implementation. I dont
> >> understand the point of this line:
> >> =A0 =A0 if (Thread.interrupted()) throw new InterruptedException();
>
> > If interrupt has been called on the thread, then you do not
> > want to start waiting !?!?
>
> Is that simply a performance optimization? =A0If not, it looks like
> there's a race condition, because the thread can get interrupted
> after that 'if'-statement completes but before entering the
> 'synchronized' block.
>
> Or to put it a different way, if the thread is interrupted, this
> code doesn't seem to guarantee that you won't start waiting.

I agree with you that it is an optimisation. However, since it is only
an optimisation, a race condition does not harm.

On the other hand, the check (Thread.interrupted()) is always added to
the call so it is also optimised for the interrupt rather than for the
normal case.

Best Regards,
Szabolcs
 




 5 Posts in Topic:
In Mutex.aquire why do we need to throw InterruptedException
puzzlecracker <ironsel  2008-05-11 15:13:10 
Re: In Mutex.aquire why do we need to throw InterruptedException
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-11 18:24:39 
Re: In Mutex.aquire why do we need to throw InterruptedException
Logan Shaw <lshaw-usen  2008-05-11 19:51:45 
Re: In Mutex.aquire why do we need to throw InterruptedException
=?ISO-8859-1?Q?Arne_Vajh=  2008-05-11 21:24:59 
Re: In Mutex.aquire why do we need to throw InterruptedException
Szabolcs Ferenczi <sza  2008-05-12 08:49:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 18:59:13 CST 2008.