From b0e927fed51bc519da7f745047be7a3fe8296219 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Jul 2015 23:23:03 +0000 Subject: [PATCH] Go Scheduler issue with sync.Mutex using gccgo Signed-off-by: Srini Brahmaroutu --- ioutils/readers.go | 1 + ioutils/readers_test.go | 2 +- ioutils/scheduler.go | 6 ++++++ ioutils/scheduler_gccgo.go | 13 +++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ioutils/scheduler.go create mode 100644 ioutils/scheduler_gccgo.go diff --git a/ioutils/readers.go b/ioutils/readers.go index 0e542cb..de15a00 100644 --- a/ioutils/readers.go +++ b/ioutils/readers.go @@ -189,6 +189,7 @@ func (r *bufReader) drain() { reuseCount++ r.wait.Signal() r.Unlock() + callSchedulerIfNecessary() if err != nil { break } diff --git a/ioutils/readers_test.go b/ioutils/readers_test.go index d220487..0a39b6e 100644 --- a/ioutils/readers_test.go +++ b/ioutils/readers_test.go @@ -45,7 +45,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) { func TestReaderErrWrapperRead(t *testing.T) { reader := strings.NewReader("a string reader.") wrapper := NewReaderErrWrapper(reader, func() { - t.Fatalf("readErrWrapper should not have called the anonymous function on failure") + t.Fatalf("readErrWrapper should not have called the anonymous function") }) // Read 20 byte (should be ok with the string above) num, err := wrapper.Read(make([]byte, 20)) diff --git a/ioutils/scheduler.go b/ioutils/scheduler.go new file mode 100644 index 0000000..3c88f29 --- /dev/null +++ b/ioutils/scheduler.go @@ -0,0 +1,6 @@ +// +build !gccgo + +package ioutils + +func callSchedulerIfNecessary() { +} diff --git a/ioutils/scheduler_gccgo.go b/ioutils/scheduler_gccgo.go new file mode 100644 index 0000000..c11d02b --- /dev/null +++ b/ioutils/scheduler_gccgo.go @@ -0,0 +1,13 @@ +// +build gccgo + +package ioutils + +import ( + "runtime" +) + +func callSchedulerIfNecessary() { + //allow or force Go scheduler to switch context, without explicitly + //forcing this will make it hang when using gccgo implementation + runtime.Gosched() +}