Skip to content

Instantly share code, notes, and snippets.

@fredreichbier
Created August 14, 2013 12:44
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 fredreichbier/6230727 to your computer and use it in GitHub Desktop.
Save fredreichbier/6230727 to your computer and use it in GitHub Desktop.
no me gusta
$ ./test-threading
false returned 0
true returned 1
false returned 1
true returned 0
true returned 1
false returned 0
...
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