Last active
August 29, 2015 14:20
-
-
Save rdarder/1bcec19085e4ade69dd7 to your computer and use it in GitHub Desktop.
ornamental gardens, failing turnstiles
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 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