[concurrency-interest] thread queueing qn

David Holmes dcholmes at optusnet.com.au
Mon Jan 21 21:30:16 EST 2008

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.

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)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080122/f550fbfa/attachment.html 

More information about the Concurrency-interest mailing list