4 ms·
For thread safety, you only want locks if your variable is shared. And even then consider using "sync.atomic" compare and swap operations instead. It's often p
by JulianMorrison 12y ago
For thread safety, you only want locks if your variable is shared. And even then consider using "sync.atomic" compare and swap operations instead.
It's often possible to avoid sharing by passing discrete data around via channels. As a general rule, if it only has one owner, it's thread safe.