]> Cypherpunks repositories - gostls13.git/commit
runtime/race: more precise handling of channel synchronization
authorDmitriy Vyukov <dvyukov@google.com>
Tue, 8 Apr 2014 06:18:20 +0000 (10:18 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Tue, 8 Apr 2014 06:18:20 +0000 (10:18 +0400)
commit9e1cadad0f64698636d4dd7a3543619b3cb269a3
tree9ac9cf96d9dd7598b612de1b7d3a75771408408a
parentf4ecfaa442ffdcab83bf63b2d40c67290d13f618
runtime/race: more precise handling of channel synchronization
It turns out there is a relatively common pattern that relies on
inverted channel semaphore:

gate := make(chan bool, N)
for ... {
        // limit concurrency
        gate <- true
        go func() {
                foo(...)
                <-gate
        }()
}
// join all goroutines
for i := 0; i < N; i++ {
        gate <- true
}

So handle synchronization on inverted semaphores with cap>1.
Fixes #7718.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/84880046
src/pkg/runtime/chan.goc
src/pkg/runtime/race/testdata/chan_test.go