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

Function incCounter

chapter6/listing13/listing13.go:37–48  ·  view source on GitHub ↗

incCounter increments the package level counter variable.

(id int)

Source from the content-addressed store, hash-verified

35
36// incCounter increments the package level counter variable.
37func incCounter(id int) {
38 // Schedule the call to Done to tell main we are done.
39 defer wg.Done()
40
41 for count := 0; count < 2; count++ {
42 // Safely Add One To Counter.
43 atomic.AddInt64(&counter, 1)
44
45 // Yield the thread and be placed back in queue.
46 runtime.Gosched()
47 }
48}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected