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>
TestWeighted's runtime was roughly proportional to the number of CPUs,
so it ran a long time on PPCs (160 CPUs).
Make the number of loops in the test an inverse function of the number
of CPUs, to keep the test short.
Change-Id: Id853dbb5e5e2f9fb95966d19ef0c511e3f8080e0
Reviewed-on: https://go-review.googlesource.com/43632
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This package provides a weighted semaphore that is context-aware.
The code is derived from a similar package inside Google.
Change-Id: Id1dad96d79e8ccfd289e4299e8265aa5bdad3a5b
Reviewed-on: https://go-review.googlesource.com/38298
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>