MCPcopy Create free account
hub / github.com/goinaction/code / incCounter

Function incCounter

chapter6/listing09/listing09.go:34–51  ·  view source on GitHub ↗

incCounter increments the package level counter variable.

(id int)

Source from the content-addressed store, hash-verified

32
33// incCounter increments the package level counter variable.
34func incCounter(id int) {
35 // Schedule the call to Done to tell main we are done.
36 defer wg.Done()
37
38 for count := 0; count < 2; count++ {
39 // Capture the value of Counter.
40 value := counter
41
42 // Yield the thread and be placed back in queue.
43 runtime.Gosched()
44
45 // Increment our local value of Counter.
46 value++
47
48 // Store the value back into Counter.
49 counter = value
50 }
51}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected