I\'m trying to understand concurrency in Go. In particular, I wrote this thread-unsafe program:
package main
import
No sure, but I think that inc_x
is hogging the CPU. Since there's no IO it doesn't release control.
I found two things that solved that. One was to call runtime.GOMAXPROCS(2)
at the beginning of the program and then it'll work since now there are two threads serving goroutings. The other is to insert time.Sleep(1)
after incrementing x
.