Grokking Concurrency in Go
Vote

0% completed

​

Atomic Operations

Eight goroutines add one to a shared counter 25,000 times each, which makes 200,000 increments. With a sync.Mutex around count++, six runs on one computer took between 13 and 28 nanoseconds per increment. With a single CPU instruction that adds one to memory in a way no other core can interrupt, the same runs took between 10 and 13 nanoseconds.

Both versions printed the correct total of 200,000 every time. The difference is in how they get there. The mutex makes each goroutine take a lock, update the variable, and release the lock

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content