This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gccgo] Avoid race condition


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
 		}
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]