diff options
author | Adam Langley <agl@golang.org> | 2009-12-18 12:25:53 -0800 |
---|---|---|
committer | Adam Langley <agl@golang.org> | 2009-12-18 12:25:53 -0800 |
commit | c5bb8463db87b715a9b27fc50e93e8fda09ece33 (patch) | |
tree | 402229af2bae3c4bff0aa3489637389c3a4e590b /test/golden.out | |
parent | 26fae9eb1b943d64fcc81cfd7a98379a48db922c (diff) | |
download | go-c5bb8463db87b715a9b27fc50e93e8fda09ece33.tar.gz |
runtime: fix race condition
(Thanks to ken and rsc for pointing this out)
rsc:
ken pointed out that there's a race in the new
one-lock-per-channel code. the issue is that
if one goroutine has gone to sleep doing
select {
case <-c1:
case <-c2:
}
and then two more goroutines try to send
on c1 and c2 simultaneously, the way that
the code makes sure only one wins is the
selgen field manipulation in dequeue:
// if sgp is stale, ignore it
if(sgp->selgen != sgp->g->selgen) {
//prints("INVALID PSEUDOG POINTER\n");
freesg(c, sgp);
goto loop;
}
// invalidate any others
sgp->g->selgen++;
but because the global lock is gone both
goroutines will be fiddling with sgp->g->selgen
at the same time.
This results in a 7% slowdown in the single threaded case for a
ping-pong microbenchmark.
Since the cas predominantly succeeds, adding a simple check first
didn't make any difference.
R=rsc
CC=golang-dev
http://codereview.appspot.com/180068
Diffstat (limited to 'test/golden.out')
-rw-r--r-- | test/golden.out | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/test/golden.out b/test/golden.out index 9813c8313..063feccd0 100644 --- a/test/golden.out +++ b/test/golden.out @@ -75,6 +75,9 @@ abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz-abcxyz == chan/ +=========== chan/doubleselect.go +PASS + =========== chan/nonblock.go PASS |