wdv4758h / data-race-test

Automatically exported from code.google.com/p/data-race-test
0 stars 2 forks source link

Go does not handle timers #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following test from std lib:

func TestAfterFunc(t *testing.T) {
    i := 10
    c := make(chan bool)
    var f func()
    f = func() {
        i--
        if i >= 0 {
            AfterFunc(0, f)
            Sleep(1 * Second)
        } else {
            c <- true
        }
    }

    AfterFunc(0, f)
    <-c
}

yields the following reports:

WARNING: Possible data race during write of size 1 at 0xf840077998: {{{
   T5 (L{}):
    #0  time_test._func_002 src/pkg/time/sleep_test.go:39
    #1  runtime.goexit src/pkg/runtime/proc.c:266
  Concurrent write(s) happened at (OR AFTER) these points:
   T4 (L{}):
    #0  time_test.TestAfterFunc src/pkg/time/sleep_test.go:35
    #1  testing.tRunner src/pkg/testing/testing.go:226
    #2  runtime.goexit src/pkg/runtime/proc.c:266
  Location 0xf840077998 is 0 bytes inside a block starting at 0xf840077998 of size 8 allocated by T4 from heap:
    #0   
    #1  testing.tRunner src/pkg/testing/testing.go:226
    #2  runtime.goexit src/pkg/runtime/proc.c:266
   Race verifier data: 0x42eaa8,0x424129
}}}
WARNING: Possible data race during read of size 1 at 0xf8400779a8: {{{
   T5 (L{}):
    #0  time_test._func_002 src/pkg/time/sleep_test.go:41
    #1  runtime.goexit src/pkg/runtime/proc.c:266
  Concurrent write(s) happened at (OR AFTER) these points:
   T4 (L{}):
    #0  time_test.TestAfterFunc src/pkg/time/sleep_test.go:46
    #1  testing.tRunner src/pkg/testing/testing.go:226
    #2  runtime.goexit src/pkg/runtime/proc.c:266
  Location 0xf8400779a8 is 0 bytes inside a block starting at 0xf8400779a8 of size 8 allocated by T4 from heap:
    #0   
    #1  testing.tRunner src/pkg/testing/testing.go:226
    #2  runtime.goexit src/pkg/runtime/proc.c:266
   Race verifier data: 0x42eadb,0x4241a6
}}}

The race are on the vars i and f, timer setup must happen-before timer body.

Original issue reported on code.google.com by dvyu...@google.com on 16 Jan 2012 at 7:22

GoogleCodeExporter commented 9 years ago

Original comment by dvyu...@google.com on 16 Jan 2012 at 8:39

GoogleCodeExporter commented 9 years ago

Original comment by mpime...@google.com on 20 Jan 2012 at 1:57