My software compiles and runs fine but when I add the -race option to check for race conditions it does not build:
GOROOT=C:\Go
GOPATH=<deleted>;D:\Golang
C:\Go\bin\go.exe build -race -o C:\Users\Andrewp\AppData\Local\Temp\___1Race_Detector.exe -gcflags "-N -l" -a <deleted>
# runtime/cgo
gcc_libinit_windows.c: In function 'x_cgo_sys_thread_create':
gcc_libinit_windows.c:56:12: error: implicit declaration of function '_beginthread' [-Werror=implicit-function-declaration]
thandle = _beginthread(func, 0, arg);
^
cc1: all warnings being treated as errors
Compilation finished with exit code 2
Note that it worked previously but I have since upgraded to go version go1.9.2 windows/amd64 (though I don't think that is related). Also have MSYS installed.
Also I am building with GoLand (under Windows 10) but I get the same problem when I build from the command line.
Does anyone have info on how the Go compiler works esp. when using race detector or cgo, so I can track down the cause of this?
Extra info: I can build fine from the terminal using:
go build -race
It seems that the problem is caused by the -a option that GoLand added to the command line since this almost identical command line fails:
go build -race -a .
But this is OK:
go build -a .
go run -race . To detect it, the code should run in heavy load, and race conditions must be occurring. You can see the output of the race condition checker. It complains about unsynchronized data access.
Memory access synchronization primitives in Golang allow your program to lock and unlock operations so that they can run in a concurrency-safe manner. This ensures that a program that shares data among different goroutines runs correctly and avoids data race conditions.
Race detection is the procedure of identifying race conditions in parallel programs and program executions. Unintended race conditions are a common source of error in parallel programs and hence race detection methods play an important role in debugging such errors.
It seems that the problem is caused by the -a option that GoLand added to the command line since this almost identical command line fails: go build -race -a . go build -a . Show activity on this post. Details are in this issue . A workaround is usually to set -vet=off
While Go’s concurrency mechanisms make it easy to write clean concurrent code, they don’t prevent race conditions. Care, diligence, and testing are required. And tools can help. We’re happy to announce that Go 1.1 includes a race detector , a new tool for finding race conditions in Go code.
The technology was integrated with Go in September 2012; since then it has detected 42 races in the standard library. It is now part of our continuous build process, where it continues to catch race conditions as they arise. The race detector is integrated with the go tool chain.
It is currently available for Linux, OS X, and Windows systems with 64-bit x86 processors. The race detector is based on the C/C++ ThreadSanitizer runtime library , which has been used to detect many errors in Google’s internal code base and in Chromium .
Details are in this issue.
A workaround is usually to set -vet=off
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With