Skip to content

Instantly share code, notes, and snippets.

@Perlence
Created January 31, 2015 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Perlence/42dae1c52408069114e5 to your computer and use it in GitHub Desktop.
Save Perlence/42dae1c52408069114e5 to your computer and use it in GitHub Desktop.
Semaphore in Go
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