October 2016: Barriers
Meetup #33. Please RSVP at Meetup.
We get started at 6:30 pm.
Sponsors
Venue provided by Startup Edmonton.
Food sponsored by Bellstone Engineering.
Talks
Barrier Pattern in Go (with Context)
Gerrit Renker examined the barrier pattern as a way to fan out work to multiple goroutines and wait for all of them to finish. He began with context.Context — its Done, Err, Deadline, and Value methods, the convention of passing it as the first argument, and how WithCancel/WithDeadline/WithTimeout form nested trees that can cancel whole groups of goroutines. From there he introduced the barrier itself: sync.WaitGroup, the Go equivalent of the classic fork-join pattern, along with its pitfalls (such as a goroutine panicking before calling Done). The second half covered golang.org/x/sync/errgroup, which extends WaitGroup with error capture and cancellation — its Go and Wait methods, how Wait returns the first error and triggers cancel, and why that matters for cancelling sibling work when one task fails. He closed with a worked example spawning stub VMs in parallel.
Key points:
context.Contextcarries cancellation, deadlines, and values down a call tree.- Pass
ctxas the first argument; derive children withWithCancel/WithTimeout. sync.WaitGroupimplements the fork-join barrier pattern.- A panic before
wg.Done()can leave the barrier stuck. errgroup.Groupadds error capture and cancellation toWaitGroup.- On first error, errgroup cancels the shared context to stop sibling work.
- Useful for fan-out tasks like provisioning resources in parallel.
Video: Idiomatic Go Tricks
News
- Go 1.7.3 released
- dotGo videos are being posted
- Go 1.8 compiler is 12% faster (so far)
Events
- Monthly Hack Day - Nov 5
- Edmonton Go Meetup - November