Text file src/cmd/go/testdata/script/cgo_bindings_race.txt

     1  # Test that -race works with CGO_ENABLED=bindings and no C toolchain,
     2  # and that it still requires cgo with CGO_ENABLED=0.
     3  
     4  env GOEXPERIMENT=$GOEXPERIMENT,runtimecgopurego,cgobindings
     5  [!GOEXPERIMENT:cgobindings] skip
     6  [!race] skip
     7  [short] skip
     8  
     9  [!GOOS:windows] env CC=/bin/false
    10  [GOOS:windows] env CC=nonexistent-cc
    11  env CGO_ENABLED=bindings
    12  ! go run -race racy.go
    13  stderr 'WARNING: DATA RACE'
    14  
    15  # On macOS, -race does not require cgo.
    16  [GOOS:darwin] stop
    17  env CGO_ENABLED=0
    18  ! go build -race racy.go
    19  stderr '^go: -race requires cgo; enable cgo by setting CGO_ENABLED=1 or CGO_ENABLED=bindings$'
    20  
    21  -- racy.go --
    22  package main
    23  
    24  import "fmt"
    25  
    26  func main() {
    27  	x := 0
    28  	done := make(chan bool)
    29  	go func() {
    30  		x = 1
    31  		done <- true
    32  	}()
    33  	x = 2
    34  	<-done
    35  	fmt.Println(x)
    36  }
    37  

View as plain text