semaphore: add worker-pool example

I've commented several times in various forums that basically every
time I've seen the “worker goroutine” pattern in Go, there has turned
out to be a cleaner implementation using semaphores.

This change adds a simple such example. (For more complex usage, I
would generally pair the semaphore with an errgroup.Group.)

Change-Id: Ibf69ee761d14ba59c1acc6a2d595b4fcf0d8f6d6
Reviewed-on: https://go-review.googlesource.com/75170
Reviewed-by: Ross Light <light@google.com>
3 files changed
tree: c8c31ae6a61f1327cdaa14f00685fb9708454466
  1. AUTHORS
  2. CONTRIBUTING.md
  3. CONTRIBUTORS
  4. LICENSE
  5. PATENTS
  6. README.md
  7. codereview.cfg
  8. errgroup/
  9. semaphore/
  10. singleflight/
  11. syncmap/
README.md

Go Sync

This repository provides Go concurrency primitives in addition to the ones provided by the language and “sync” and “sync/atomic” packages.

Download/Install

The easiest way to install is to run go get -u golang.org/x/sync. You can also manually git clone the repository to $GOPATH/src/golang.org/x/sync.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the sync repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/sync:” in the subject line, so it is easy to find.