Skip to content

Instantly share code, notes, and snippets.

@rdarder
Last active August 29, 2015 14:20
Show Gist options
  • Save rdarder/1bcec19085e4ade69dd7 to your computer and use it in GitHub Desktop.
Save rdarder/1bcec19085e4ade69dd7 to your computer and use it in GitHub Desktop.
ornamental gardens, failing turnstiles
package main
import "fmt"
var counter = 0
func turnstile(turns int, done chan bool){
for i := 0; i < turns; i++{
counter = counter + 1
}
done <- true
}
func main(){
done := make(chan bool)
turns := 1000
turnstiles := 2
for ts := 0; ts < turnstiles; ts++ {
go turnstile(turns, done)
}
for ts := 0; ts < turnstiles; ts++ {
<- done
}
fmt.Printf("After %d * %d turns, got %d\n", turns, turnstiles, counter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment