File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,21 +44,21 @@ func incCounter(id int) {
4444 // Only allow one goroutine through this
4545 // critical section at a time.
4646 mutex .Lock ()
47+ {
48+ // Capture the value of counter.
49+ value := counter
4750
48- // Capture the value of counter .
49- value := counter
51+ // Yield the thread and be placed back in queue .
52+ runtime . Gosched ()
5053
51- // Yield the thread and be placed back in queue.
52- runtime .Gosched ()
53-
54- // Increment our local value of counter.
55- value ++
56-
57- // Store the value back into counter.
58- counter = value
54+ // Increment our local value of counter.
55+ value ++
5956
57+ // Store the value back into counter.
58+ counter = value
59+ }
60+ mutex .Unlock ()
6061 // Release the lock and allow any
6162 // waiting goroutine through.
62- mutex .Unlock ()
6363 }
6464}
You can’t perform that action at this time.
0 commit comments