Sunday, 10 April 2016

What are Barriers and how they works ?


Barriers
  • similar to Latches
  • blocks n threads until some event has occurred
  • In order to proceed, n must come together at a barrier point at the same time.

How Barriers works ?
  • After reaching at barrier point, thread calls await() method.
  • await() blocks until all the threads have reached the barrier point.
  • When all threads arrives at the barrier point
    • Barrier is passed
    • All threads are released
    • Barrier is reset so it can be used again. 
    • await() returns a unique arrival index for each thread
  • If a call to await()times out or a thread blocked in await() is interrupted
    • Barrier is broken
    • All other calls to await() terminate with BrokenBarrierException.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.