1
0
mirror of https://github.com/golang/go synced 2024-10-04 11:21:21 -06:00
go/src
Ian Lance Taylor 9a2f0029bc io: Avoid another race condition in pipes.
Goroutine 1:
  Call Read on read half of pipe, entering pipeHalf.rw.
  Check ioclosed field, which is false.
  Send data to p.c1
  Wait for response on p.c2.

Goroutine 2:
  Call Close on read half of pipe, entering pipeHalf.close.
  Set closed field.
  Send error to p.cclose.
  Set ioclosed field.
  Send 1 to p.done.
  Return and exit goroutine.

Goroutine 3:
  This is the goroutine running pipe.run, and for some reason
  it has started late.
  Read error from p.rclose; set rerr and continue.
  Read 1 from p.done; increment ndone and continue.
  Read data from r1 (sent by goroutine 1); set r1 = nil and continue

Now goroutine 1 is waiting for a response, and goroutine 3 is
waiting for something else to happen.

This patch fixes the race by having the runner check whether
the read half is closed when it is asked for read data, and
similarly for the corresponding race on the write half.

This patch also fixes the similar race in which ndone gets
bumped up to 2 while there is a reader or writer waiting.

There is still another race to fix.  It is possible for the
read half and the write half to both be closed, and for the
runner goroutine to exit, all before the runner goroutine sees
the request from a reader.  E.g., in the above, have goroutine
2 also close the write half, and have goroutine 3 see both
done messages before it sees the request from goroutine 1.

R=rsc
CC=golang-dev
https://golang.org/cl/1862045
2010-07-21 10:57:46 -07:00
..
cmd arm: fix build by disabling list copying optimization for 5g. 2010-07-21 14:14:21 +03:00
lib9 rename GOOS=mingw to GOOS=windows 2010-04-29 23:45:14 -07:00
libbio Ports of lib9, libbio and libmach to Windows. 2009-11-30 11:53:11 -08:00
libcgo linux/386: use Xen-friendly ELF TLS instruction sequence 2010-07-17 16:54:03 -07:00
libmach 6a: assemble CMPPD as 6l expects 2010-07-01 12:36:29 -07:00
pkg io: Avoid another race condition in pipes. 2010-07-21 10:57:46 -07:00
all-arm.bash arm: toss make-arm.bash 2010-02-03 20:46:37 -08:00
all-nacl.bash nacl: another attempt at fixing build 2010-05-03 11:12:54 -07:00
all.bash build script tweaks 2010-03-31 19:48:33 -07:00
clean.bash add simple garbage collector benchmarks to dashboard 2010-02-09 13:33:00 -08:00
env.bash rename GOOS=mingw to GOOS=windows 2010-04-29 23:45:14 -07:00
Make.386 makefile fixes; convert runtime to use new makefiles 2009-08-13 14:41:10 -07:00
Make.amd64 makefile fixes; convert runtime to use new makefiles 2009-08-13 14:41:10 -07:00
Make.arm makefile fixes; convert runtime to use new makefiles 2009-08-13 14:41:10 -07:00
make.bash Build libcgo.so with $(CC), not the gcc on PATH. 2010-07-15 14:15:39 -07:00
Make.cmd windows: append executable extension (done as per Russ' suggestion) 2010-07-14 17:21:13 -07:00
Make.common Factor the Makefiles to make writing outside Makefiles easier. 2010-03-19 15:14:46 -07:00
Make.conf Fix missing explicit GOBIN in src/pkg/Makefile. Clean up creation of 2010-01-06 07:47:56 -08:00
Make.pkg cgo: use new command line syntax: -- separates cgo flags from gcc flags 2010-07-15 09:41:21 -07:00
quietgcc.bash Build changes to support work on the BSDs. 2009-11-14 15:29:09 -08:00
run.bash run.bash: remove MAKEFLAGS=-j4 to prevent crashing on freebsd 2010-04-05 10:53:38 +10:00
sudo.bash go: makes it build for the case $GOROOT has whitespaces 2009-11-23 17:32:51 -08:00
version.bash version.bash: cope with ancient Mercurial 2010-03-16 18:45:06 -07:00