How does Go decide use which "raceenabled" (race.go or race0.go)?

187 views
Skip to first unread message

Nan Xiao

unread,
Jun 25, 2015, 1:23:14 AM6/25/15
to golan...@googlegroups.com
Hi,

I am reading waitgroup.go code, and find it uses "raceenabled". I also find raceenabled in both "race.go" 
and "race0.go" (one is "true", while the other is "false").  How do I know which one is my Go program use? 

Thanks in advance!

Best Reagrds
Nan Xiao

Andrew Gerrand

unread,
Jun 25, 2015, 1:38:38 AM6/25/15
to Nan Xiao, golang-nuts
The raceenabled boolean is true when the race detector is enabled.

If you look at the top of each file, you can see that race.go has the line
  // +build race
and race0.go has the line
  // +build !race

This means that the former file will be compiled when the "race" build tag is set, and the other will be compiled when the "race" tag is not set.

Compiling your code with the race detector enabled (by passing the -race flag to the go tool) will cause that build tag to be set.

More detail on the race detector:
  http://blog.golang.org/race-detector

Andrew

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nan Xiao

unread,
Jun 25, 2015, 1:41:21 AM6/25/15
to Andrew Gerrand, Nan Xiao, golang-nuts
Got it! Thanks very much for your answer!

Best Regards
Nan Xiao

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/VL8m9WHL6o8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages