go/test/chan
Adam Langley 50d6c81d4a 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
https://golang.org/cl/180068
2009-12-18 12:25:53 -08:00
..
doubleselect.go runtime: fix race condition 2009-12-18 12:25:53 -08:00
fifo.go move things out of sys into os and runtime 2009-05-08 15:21:41 -07:00
goroutines.go move things out of sys into os and runtime 2009-05-08 15:21:41 -07:00
nonblock.go move things out of sys into os and runtime 2009-05-08 15:21:41 -07:00
perm.go last round: non-package code 2009-09-15 12:42:24 -07:00
powser1.go making some more non-gofmt'ed files save for new semicolon rule 2009-12-09 19:27:08 -08:00
powser2.go missed a couple of files in test 2009-12-09 21:39:20 -08:00
select.go fix up some irregular indentation 2009-08-17 13:30:22 -07:00
sieve.go Don't bother to import "os" just so that we can call 2009-05-16 23:12:28 -07:00