Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Created August 10, 2016 14:50
Show Gist options
  • Select an option

  • Save jasonkeene/d73299585966c80057404271c5216fec to your computer and use it in GitHub Desktop.

Select an option

Save jasonkeene/d73299585966c80057404271c5216fec to your computer and use it in GitHub Desktop.
type lock struct {
l uint32
}
func (l *lock) Lock() {
for {
if atomic.CompareAndSwapUint32(&l.l, 0, 1) {
return
}
}
}
func (l *lock) Unlock() {
atomic.StoreUint32(&l.l, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment