[concurrency-interest] thread queueing qn

Dhanji R. Prasanna dhanji at gmail.com
Mon Jan 21 21:44:52 EST 2008


Hmm, good call!
Some time ago I had considered using a fair lock--new ReentrantLock(true);

"When set true, under contention, locks favor granting access to the
longest-waiting thread. "


Does this mean longest-waiting threads with be notified first? Given that a
request thread is unlikely to reenter a held lock, this should provide me
with FIFO semantics should it not?

Dhanji.

On 1/22/08, David Holmes <dcholmes at optusnet.com.au> wrote:
>
>  If there are only two threads then what you describe is correct. But let
> there be three threads:
>
> - Thread A acquires L
> - Thread B attepts L, but L is locked, so it blocks
> - Thread C attepts L, but L is locked, so it blocks
> - Thread A releases L
>
> At this point there is no guarantee whether B will be woken to try and
> acquire L, or whether C will be woken, or both. Even if B or C were awoken,
> thread D might barge in and grab L first.
>
> It's all up to the implementation.
>
> Cheers,
> David Holmes
>
> -----Original Message-----
> *From:* Dhanji R. Prasanna [mailto:dhanji at gmail.com]
> *Sent:* Tuesday, 22 January 2008 12:21 PM
> *To:* dholmes at ieee.org
> *Cc:* Bob Lee; concurrency-interest
> *Subject:* Re: [concurrency-interest] thread queueing qn
>
>
>
> On 1/22/08, David Holmes <dcholmes at optusnet.com.au> wrote:
> >
> >  No it doesn't mean that. There's no guarantee of FIFO access to a
> > synchronized region.
> >
>
>
> I don't think I follow. Let's do this in the abstract (i.e. not
> necessarily Java):
>
>
> Threads: [A, B] Locks: [L]
>
>
> - Thread A acquires L
> - Thread B attempts L, but L is locked, so it blocks
> - Thread A completes critical section and releases L
> - Thread B is notified, and continues into the critical section
>
>
> A came first, A exited first. B came last, B exited last.
>
>
> Does j.u.c.l.Lock or java monitors not guarantee such ordering (i.e. on
> acquisition or release of locks)?
>
>
> Dhanji.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080122/a3e2592b/attachment.html 


More information about the Concurrency-interest mailing list