Why does the following program hang when the time.Sleep(time.Nanosecond)
is commented out?
package main
import "fmt"
import "time"
import "sync/atomic"
func main() {
var ops uint64 = 0
for i := 0; i < 50; i++ {
go func() {
for {
atomic.AddUint64(&ops, 1)
time.Sleep(time.Nanosecond)
}
}()
}
time.Sleep(time.Millisecond)
opsFinal := atomic.LoadUint64(&ops)
fmt.Println("ops:", opsFinal)
}
Second question, why does running this program in the sandbox result in "process took too long"?