From 917c5fb8ec48e22459d77e3849e6d388f93d3260 Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Thu, 14 Jun 2012 13:23:46 +0200 Subject: Imported Upstream version 1.0.2 --- src/pkg/time/sleep_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/pkg/time/sleep_test.go') diff --git a/src/pkg/time/sleep_test.go b/src/pkg/time/sleep_test.go index 526d58d75..e05773df6 100644 --- a/src/pkg/time/sleep_test.go +++ b/src/pkg/time/sleep_test.go @@ -223,3 +223,25 @@ func TestTimerStopStress(t *testing.T) { } Sleep(3 * Second) } + +func TestSleepZeroDeadlock(t *testing.T) { + // Sleep(0) used to hang, the sequence of events was as follows. + // Sleep(0) sets G's status to Gwaiting, but then immediately returns leaving the status. + // Then the goroutine calls e.g. new and falls down into the scheduler due to pending GC. + // After the GC nobody wakes up the goroutine from Gwaiting status. + defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4)) + c := make(chan bool) + go func() { + for i := 0; i < 100; i++ { + runtime.GC() + } + c <- true + }() + for i := 0; i < 100; i++ { + Sleep(0) + tmp := make(chan bool, 1) + tmp <- true + <-tmp + } + <-c +} -- cgit v1.2.3