Threading - qlova/ilang GitHub Wiki
New threads can be created with the fork keyword, which allows you to start a function in a new thread.
function spin() {
loop {} //Loop forever.
}
fork spin()
print("This still prints!")
You can pass arguments like a normal function does, although you cannot return values. In order to communicate between threads you need to use pipes or the Mailbox system.
The MailBox system is a default pipe that connects your thread with its creator.
function sendHelloWorld() {
outbox("Hello World")
}
fork sendHelloWorld()
print(inbox())
You can also create your own pipe.
function communicateWithMe(||channel) {
var m = channel()
print("You sent me: ", m)
outbox("I sent you this")
}
var p = ||
fork communicateWithMe(p)
p("Hello thread")
print("Reply: ", inbox())