Created
August 14, 2013 12:44
-
-
Save fredreichbier/6230727 to your computer and use it in GitHub Desktop.
no me gusta
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
$ ./test-threading | |
false returned 0 | |
true returned 1 | |
false returned 1 | |
true returned 0 | |
true returned 1 | |
false returned 0 | |
... |
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 os/Process | |
import os/Time | |
import threading/Thread | |
Runner: class { | |
exec: String | |
init: func (=exec) {} | |
run: func -> Int { | |
Process new([exec]) execute() | |
} | |
runForever: func { | |
while(true) { | |
ret := run() | |
"%s returned %d" printfln(exec, ret) | |
Time sleepSec(1) | |
} | |
} | |
} | |
threads := ArrayList<Thread> new() | |
threads add(Thread new(|| | |
r := Runner new("true") | |
r runForever() | |
)) | |
threads add(Thread new(|| | |
r := Runner new("false") | |
r runForever() | |
)) | |
threads each(|t| t start()) | |
threads each(|t| t wait()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment