Skip to content

Instantly share code, notes, and snippets.

@amsokol
Created January 25, 2019 14:02
Show Gist options
  • Save amsokol/0853f7e93914dcc5a2f025ff1d32a7f1 to your computer and use it in GitHub Desktop.
Save amsokol/0853f7e93914dcc5a2f025ff1d32a7f1 to your computer and use it in GitHub Desktop.
mutex-ex.go
package importer
type MutexEx struct {
c chan bool
}
func (m *MutexEx) Lock() {
<-m.c
}
func (m *MutexEx) Unlock() {
m.c <- true
}
func newMutexEx(threshold int) *MutexEx {
m := MutexEx{c: make(chan bool, threshold)}
for i := 0; i < threshold; i++ {
m.c <- true
}
return &m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment