https://github.com/db7/barrier
A barrier to synchronize a group of goroutines with an optional callback executed in isolation.
https://github.com/db7/barrier
Last synced: 12 months ago
JSON representation
A barrier to synchronize a group of goroutines with an optional callback executed in isolation.
- Host: GitHub
- URL: https://github.com/db7/barrier
- Owner: db7
- License: mit
- Created: 2016-10-24T10:01:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-25T08:17:03.000Z (over 9 years ago)
- Last Synced: 2025-03-05T22:47:41.315Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# barrier
[](https://godoc.org/github.com/db7/barrier)
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](http://www.gofragments.net/client/blog/concurrency/2015/11/09/cyclicBarrierMutexChan/index.html).