From 2d0927a08b5cdb7a974f845b097d60f1255d755d Mon Sep 17 00:00:00 2001 From: Srini Brahmaroutu Date: Fri, 25 Sep 2015 00:13:38 +0000 Subject: [PATCH] goroutine fairness is not guaranteed causing the hang with GCCGO Signed-off-by: Srini Brahmaroutu --- ioutils/readers.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ioutils/readers.go b/ioutils/readers.go index 6b9637a..54dd312 100644 --- a/ioutils/readers.go +++ b/ioutils/readers.go @@ -84,6 +84,9 @@ func NewBufReaderWithDrainbufAndBuffer(r io.Reader, drainBuffer []byte, buffer i func (r *bufReader) drain() { for { + //Call to scheduler is made to yield from this goroutine. + //This avoids goroutine looping here when n=0,err=nil, fixes code hangs when run with GCC Go. + callSchedulerIfNecessary() n, err := r.reader.Read(r.drainBuf) r.Lock() if err != nil { @@ -98,7 +101,6 @@ func (r *bufReader) drain() { } r.wait.Signal() r.Unlock() - callSchedulerIfNecessary() if err != nil { break }