• Adam Langley's avatar
    runtime: fix race condition · 50d6c81d
    Adam Langley authored
    (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
    50d6c81d
Name
Last commit
Last update
..
doubleselect.go Loading commit data...
fifo.go Loading commit data...
goroutines.go Loading commit data...
nonblock.go Loading commit data...
perm.go Loading commit data...
powser1.go Loading commit data...
powser2.go Loading commit data...
select.go Loading commit data...
sieve.go Loading commit data...