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

How does the mod work?

Started by Piorjade, 04 December 2016 - 07:56 PM
Piorjade #1
Posted 04 December 2016 - 08:56 PM
I already know that a computer doesn't have real multitasking and that using coroutines is just rapidly going through every of them when they yield but how does it work with the mod and the computers?
I mean having 2 computers at the same time. Does the mod run them like REALLY at the same time or is it some illusion again?
supernicejohn #2
Posted 04 December 2016 - 09:12 PM
I think they all share the same vm, and that all computers have their own coroutine, which probably is one of the reasons the 'too long without yielding' error occurs, so that other coroutines/computers can be resumed even if one computer was to lock up. I've seen the question related to cc emulators, and if I recall correctly the game does the same. Could be wrong, so feel free to correct me ;)/>
Bomb Bloke #3
Posted 04 December 2016 - 09:21 PM
That's indeed how ComputerCraft does it. On a "real" computer we've got multiple cores and preemptive multitasking, but for the purposes of the mod, so long as one system is actively running code, all of the others are in a yielding state and will stay there until the active one either yields or gets killed.
Piorjade #4
Posted 04 December 2016 - 09:34 PM
Thanks
Sewbacca #5
Posted 04 December 2016 - 10:23 PM
That's indeed how ComputerCraft does it. On a "real" computer we've got multiple cores and preemptive multitasking, but for the purposes of the mod, so long as one system is actively running code, all of the others are in a yielding state and will stay there until the active one either yields or gets killed.
But from Lua, it isn't possible to kill processes (How can a yielding coroutine work?), right?
Edited on 04 December 2016 - 09:24 PM
KingofGamesYami #6
Posted 04 December 2016 - 11:03 PM
ComputerCraft is able to kill processes because it's not part of the lua it's executing and is in a preemptive multitasking environment (Java).
Sewbacca #7
Posted 03 January 2017 - 12:44 AM
ComputerCraft is able to kill processes because it's not part of the lua it's executing and is in a preemptive multitasking environment (Java).
I think it's important for the event queue, that all computers don't work asynchron.
If one computer works without yielding, the others would get events, which this one doesn't get.
KingofGamesYami #8
Posted 03 January 2017 - 12:56 AM
On the contrary, that computer would get events, it simply would not be able to act on them, as it never asks for one. In fact, CCTweaks allows up to 4 computers to execute simultaneously with no issues (they are still forced to yield eventually though)
Sewbacca #9
Posted 03 January 2017 - 11:02 PM
On the contrary, that computer would get events, it simply would not be able to act on them, as it never asks for one. In fact, CCTweaks allows up to 4 computers to execute simultaneously with no issues (they are still forced to yield eventually though)
That's why i thought about it, but i meant a long task, not an endless one. Also asynchronous computer in a network, can occur fatal errors.