Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 1.14 KB

README.md

File metadata and controls

26 lines (19 loc) · 1.14 KB

barrier

GoDoc

Barrier is a data structure to synchronize a fixed-size group of goroutines, blocking them until all arrive on the barrier, by calling Await(). Once the last goroutine arrives, an optional callback is executed in isolation. The barrier can be immediately reused after the goroutines return from Await().

This barrier implementation supports early termination by calling Abort(). Once aborted the barrier cannot be reused. Also, if the barrier detects that Await() is concurrently called by often than the number specified in the constructor, the barrier is aborted.

Algorithm

The algorithm is pretty similar to the simple algorithm described in The Art of Multiprocessor Programming - Herlihy and Shavit. By using a mutex and creating a new channel on every reset, however, one does not have to implement a goroutine-bound sense variable.

Alternatives

A simpler version, also using channels and a mutex, can be found here.