• Dmitry Vyukov's avatar
    runtime: fix false race report during tracing · 4a45ac57
    Dmitry Vyukov authored
    Currently race detector produces the following reports on pprof tests:
    
    WARNING: DATA RACE
    Read by goroutine 4:
      runtime/pprof_test.TestTraceStartStop()
          src/runtime/pprof/trace_test.go:38 +0x1da
      testing.tRunner()
          src/testing/testing.go:448 +0x13a
    
    Previous write by goroutine 5:
      bytes.(*Buffer).grow()
          src/bytes/buffer.go:102 +0x190
      bytes.(*Buffer).Write()
          src/bytes/buffer.go:127 +0x75
      runtime/pprof.func·002()
          src/runtime/pprof/pprof.go:633 +0xae
    
    Trace writer goroutine synchronizes with StopTrace
    using trace.shutdownSema runtime semaphore.
    But race detector does not see that synchronization
    and so produces false reports.
    Teach race detector about the synchronization.
    
    Change-Id: I1219817325d4e16b423f29a0cbee94c929793881
    Reviewed-on: https://go-review.googlesource.com/3746Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    4a45ac57
trace.go 23.5 KB