Created
August 19, 2015 22:02
-
-
Save exelotl/364c23ff21c1ee000dee to your computer and use it in GitHub Desktop.
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
import structs/ArrayList | |
import threading/Thread | |
counter := 0 | |
mutex := Mutex new() | |
threads := ArrayList<Thread> new() | |
main: func { | |
for (i in 0..10) { | |
threads add(Thread new(|| | |
for (i in 0..1000) { | |
mutex lock() | |
counter += 1 | |
mutex unlock() | |
Thread yield() | |
} | |
)) | |
} | |
for (t in threads) t start() | |
for (t in threads) t wait() | |
// prints counter = ??? | |
"counter = %d" printfln(counter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment