1
0
mirror of https://github.com/golang/go synced 2024-10-04 10:21:21 -06:00
go/src/pkg/runtime
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
..
386 Fix stack on FreeBSD / add stack check across the board 2009-12-08 18:19:30 -08:00
amd64 Fix stack on FreeBSD / add stack check across the board 2009-12-08 18:19:30 -08:00
arm first stub for softfloats, intercepts float instructions and skips 2009-12-17 16:08:42 -08:00
darwin runtime: if os/signal is not in use, crash on 2009-12-16 20:20:50 -08:00
freebsd runtime: if os/signal is not in use, crash on 2009-12-16 20:20:50 -08:00
linux runtime: if os/signal is not in use, crash on 2009-12-16 20:20:50 -08:00
nacl Remove unnecessary execute bits. 2009-11-18 09:19:29 -08:00
cgo2c.c rename runtime internals to have modern names (array->slice etc) 2009-08-25 15:54:25 -07:00
cgocall.c rename sys functions to runtime, 2009-10-15 23:10:49 -07:00
cgocall.h 8c, 8l dynamic loading support. 2009-10-03 10:37:12 -07:00
chan.c runtime: fix race condition 2009-12-18 12:25:53 -08:00
extern.go runtime: if os/signal is not in use, crash on 2009-12-16 20:20:50 -08:00
float.c move math out of runtime. 2009-10-15 23:09:22 -07:00
hashmap.c rename sys functions to runtime, 2009-10-15 23:10:49 -07:00
hashmap.h x[lo:] - gc and runtime. 2009-11-20 09:11:46 -08:00
iface.c runtime: introduce unsafe.New and unsafe.NewArray 2009-12-07 15:51:58 -08:00
Makefile first stub for softfloats, intercepts float instructions and skips 2009-12-17 16:08:42 -08:00
malloc.cgo runtime: malloc fixes 2009-12-03 17:22:23 -08:00
malloc.h runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
mcache.c mv src/lib to src/pkg 2009-06-09 09:53:44 -07:00
mcentral.c runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
mem.c runtime: malloc fixes 2009-12-03 17:22:23 -08:00
mfixalloc.c mv src/lib to src/pkg 2009-06-09 09:53:44 -07:00
mgc0.c runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
mheap.c runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
mheapmap32.c runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
mheapmap32.h mv src/lib to src/pkg 2009-06-09 09:53:44 -07:00
mheapmap64.c runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
mheapmap64.h mv src/lib to src/pkg 2009-06-09 09:53:44 -07:00
mkasmh.sh mysterious bug: runtime.acid wasn't getting rebuilt 2009-10-28 14:03:16 -07:00
msize.c mv src/lib to src/pkg 2009-06-09 09:53:44 -07:00
print.c rename sys functions to runtime, 2009-10-15 23:10:49 -07:00
proc.c os/signal: new package 2009-12-15 18:21:29 -08:00
reflect.cgo reflect fixes 2009-11-19 22:06:32 -08:00
rune.c fix range on invalid utf8 bug 2009-09-03 13:56:06 -07:00
runtime.c x[lo:] - gc and runtime. 2009-11-20 09:11:46 -08:00
runtime.h runtime: fix race condition 2009-12-18 12:25:53 -08:00
sema.cgo publish semacquire and semrelease for use by sync. 2009-10-15 17:46:53 -07:00
sigqueue.cgo runtime: if os/signal is not in use, crash on 2009-12-16 20:20:50 -08:00
slice.c runtime: introduce unsafe.New and unsafe.NewArray 2009-12-07 15:51:58 -08:00
string.cgo x[y:] for strings 2009-11-20 11:42:28 -08:00
symtab.c runtime: don't touch pages of memory unnecessarily. 2009-12-07 15:52:14 -08:00
type.go 1) Change default gofmt default settings for 2009-12-15 15:40:16 -08:00
type.h gc/runtime: pass type structure to makeslice. 2009-12-04 21:44:05 -08:00