Hi, I'm trying to understand output of the "go tool trace". I'm using runtime.LockOSThread, however the output of the trace tool shows goroutines moving between procs (which I *think* are OS threads). What am I missing?
Code: package main import ( "fmt" "os" "runtime" "runtime/trace" "time" ) func sqrt(val float64) (float64, error) { if val < 0.0 { return 0.0, fmt.Errorf("sqrt of negative number") } if val == 0.0 { return 0.0, nil // shortcut } guess, epsilon := 1.0, 0.00001 for i := 0; i < 10000; i++ { diff := guess*guess - val if diff < 0 { diff = -diff } if diff <= epsilon { return guess, nil } guess = (val/guess + guess) / 2.0 } return 0.0, fmt.Errorf("can't find sqrt of %f", val) } func worker(id int) { runtime.LockOSThread() i := float64(0) for { for n := 0; n < 1000000; n++ { i += 13.2 _, err := sqrt(i) if err != nil { panic(err) } } runtime.Gosched() } } func main() { out, err := os.Create("trace.out") if err != nil { panic(err) } defer out.Close() if err := trace.Start(out); err != nil { panic(err) } defer trace.Stop() for i := 0; i < runtime.NumCPU(); i++ { go worker(i) } time.Sleep(3 * time.Second) } What I see in trace: [image: trace-out.png] Thanks, Miki -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4c797f3c-a39f-40d5-9bcd-52f88c4b3d09%40googlegroups.com.