From patchwork Wed Jul 28 14:32:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [gccgo] Avoid race condition From: Ian Taylor X-Patchwork-Id: 60148 Message-Id: To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Date: Wed, 28 Jul 2010 07:32:28 -0700 I copied this patch from the other Go library to avoid a race condition which gccgo tends to trigger when running the tests. I didn't want to take the time to do a full library upgrade right now. Committed to gccgo branch. Ian diff -r 18be60ce1a6e libgo/go/io/pipe.go --- a/libgo/go/io/pipe.go Wed Jul 28 06:47:29 2010 -0700 +++ b/libgo/go/io/pipe.go Wed Jul 28 07:30:40 2010 -0700 @@ -52,6 +52,13 @@ case <-p.done: if ndone++; ndone == 2 { // both reader and writer are gone + // close out any existing i/o + if r1 == nil { + p.r2 <- pipeResult{0, os.EINVAL} + } + if w1 == nil { + p.w2 <- pipeResult{0, os.EINVAL} + } return } continue @@ -89,6 +96,11 @@ p.r2 <- pipeResult{0, werr} continue } + if rerr != nil { + // read end is closed + p.r2 <- pipeResult{0, os.EINVAL} + continue + } r1 = nil // disable Read until this one is done case wb = <-w1: if rerr != nil { @@ -96,6 +108,11 @@ p.w2 <- pipeResult{0, rerr} continue } + if werr != nil { + // write end is closed + p.w2 <- pipeResult{0, os.EINVAL} + continue + } w1 = nil // disable Write until this one is done }