This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PrinzJuliano's profile picture

[Question]: Threads

Started by PrinzJuliano, 03 June 2013 - 09:14 AM
PrinzJuliano #1
Posted 03 June 2013 - 11:14 AM
Hello,

I got a simple question:

Can lua handle Threads(Running multiple programs at once) ???

I've seen a nice program called frames and i like to know if there is a method to create Threads
MudkipTheEpic #2
Posted 03 June 2013 - 11:18 AM
Use parallel.waitForAny or parallel.waitForAll. Example:


parallel.waitForAny(loadfile("onename"), loadfile("anothername"))

Parallel is great for basic usage.
theoriginalbit #3
Posted 03 June 2013 - 11:18 AM
Threads no, coroutines yes. Basically a coroutine only one can run at any given time, and must yield (just like the computers) to allow other coroutines to run. They run so quickly they give the appearance of running at the same time, when they actually aren't.
Implementing a coroutine system is not the easiest of task, well debatably, depends on your understanding of code and how it works/runs, and your ability with Lua, however the CC devs have been nice to those who cannot implement their own and have supplied us with the parallel api.