Commit graph

6 commits

Author SHA1 Message Date
Jean de Klerk
37e7f081c4 semaphore: add more Acquire documentation
Change-Id: Ie64db438145a307ec8aef8fd412d445a2fe74d40
Reviewed-on: https://go-review.googlesource.com/c/136995
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-21 19:32:16 +00:00
Jean de Klerk
42b317875d all: remove x/net/context in favour of context
Change-Id: Idbfe40e7cb9f99ca3dc7d4c214de6b9e028eefb7
Reviewed-on: https://go-review.googlesource.com/c/148277
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-11-08 01:04:31 +00:00
Bryan C. Mills
fd80eb99c8 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>
2017-11-01 21:47:15 +00:00
Jonathan Amsterdam
f52d1811a6 semaphore: make test time independent of GOMAXPROCS
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>
2017-05-17 21:12:32 +00:00
Jonathan Amsterdam
de49d9dcd2 semaphore: avoid loop variable capture by closure
Change-Id: I21c5dc48ffe43aa27c50a42f9c9a01ac1f0c747c
Reviewed-on: https://go-review.googlesource.com/40991
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Glenn Lewis <gmlewis@google.com>
2017-04-18 21:08:38 +00:00
Jonathan Amsterdam
5a06fca2c3 semaphore: add a weighted semaphore implementation
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>
2017-03-17 23:16:01 +00:00