[concurrency-interest] j.u.c.Phaser tutorial?

David Holmes davidcholmes at aapt.net.au
Mon Aug 1 16:27:57 EDT 2011

Not sure what you mean by "the end". The main thread calls
arriveAndDeregister to allow the first release of the barrier to occur while
at the same time removing itself from future cycles of the barrier (so the
main processing loops only require the N worker threads to meet at the
barrier). If the main thread didn't deregister then the N worker threads
would block at the barrier waiting for a non-existent N+1 thread to turn up.

  -----Original Message-----
  From: Ashwin Jayaprakash [mailto:ashwin.jayaprakash at gmail.com]
  Sent: Tuesday, 2 August 2011 6:06 AM
  To: dholmes at ieee.org
  Cc: concurrency-interest at cs.oswego.edu
  Subject: Re: [concurrency-interest] j.u.c.Phaser tutorial?

  Why doesn't the main thread just call arrive() at the end?  I guess only
for clarity - to show that only x worker threads (minus 1 starter thread)
are required for the processing.

  On Sun, Jul 31, 2011 at 3:47 PM, David Holmes <davidcholmes at aapt.net.au>


    > I learned later that the arriveAndDeregister() method makes sense only
when you create a hierarchy of phasers

    Not so. arriveAndDeregister is typically used by the main thread when
the phaser acts as both a cyclic barrier and a starting latch. You create
the phaser for N+1 threads and have all workers wait on the phaser in a
loop. The main thread is needed to release the phaser the first time so that
all workers have been created but thereafter is not needed so it can arrive
and deregister.

    David Holmes

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110802/59aa4f19/attachment.html>

More information about the Concurrency-interest mailing list