Created
January 31, 2015 21:11
-
-
Save Perlence/42dae1c52408069114e5 to your computer and use it in GitHub Desktop.
Semaphore in 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 semaphore | |
type Semaphore chan bool | |
func (self Semaphore) Acquire() { | |
self <- true | |
} | |
func (self Semaphore) Release() { | |
<-self | |
} | |
func (self Semaphore) Join() { | |
for i := 0; i < cap(self); i++ { | |
self <- true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment