Created
January 25, 2019 14:02
-
-
Save amsokol/0853f7e93914dcc5a2f025ff1d32a7f1 to your computer and use it in GitHub Desktop.
mutex-ex.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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