← Back to context

Comment by reactordev

5 days ago

    if id == 1 {
        counter++;
    }

Found your problem. /s

In all honesty, if you “do work” using channels then all your goroutines are “thread safe” as the channel keeps things in order. Also, mutex is working as intended. As you see in your post, -race sees this, it’s good. Now have one goroutine read from a chan, get rid of the mutex, all other goroutines write to the chan, perfection.