Go

Guarding Shared State in Go

GoConcurrencyMutexadvanced

counter++ is not atomic. Without the mutex the goroutines interleave and the total comes out short, a race the -race detector will flag.

expected output

100

Why practise typing this

Typing concurrency code builds muscle memory for the symbols and indentation Go uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More Go practice

Browse all Go snippets →