From 9ca913d0f168d943f6e15f32f52f777732b354a7 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 --- pkg/ioutils/readers.go | 1 + pkg/ioutils/readers_test.go | 2 +- pkg/ioutils/scheduler.go | 6 ++++++ pkg/ioutils/scheduler_gccgo.go | 13 +++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 pkg/ioutils/scheduler.go create mode 100644 pkg/ioutils/scheduler_gccgo.go diff --git a/pkg/ioutils/readers.go b/pkg/ioutils/readers.go index 0e542cbad3..de15a00648 100644 --- a/pkg/ioutils/readers.go +++ b/pkg/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/pkg/ioutils/readers_test.go b/pkg/ioutils/readers_test.go index d220487ad5..0a39b6ec6a 100644 --- a/pkg/ioutils/readers_test.go +++ b/pkg/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/pkg/ioutils/scheduler.go b/pkg/ioutils/scheduler.go new file mode 100644 index 0000000000..3c88f29e35 --- /dev/null +++ b/pkg/ioutils/scheduler.go @@ -0,0 +1,6 @@ +// +build !gccgo + +package ioutils + +func callSchedulerIfNecessary() { +} diff --git a/pkg/ioutils/scheduler_gccgo.go b/pkg/ioutils/scheduler_gccgo.go new file mode 100644 index 0000000000..c11d02b947 --- /dev/null +++ b/pkg/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() +}