lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> -----Original Message-----
> From: [] On
> Behalf Of Milind Gupta
> Sent: vrijdag 31 januari 2014 22:11
> To: Lua mailing list
> Subject: Re: Launching and controlling multiple lua scripts from Lua
> Thanks for the responses. My issue is that the scripts I want to run will be
> installed at run time and will come from a 3rd party. It will be difficult
> to plan cooperative multitasking if every script is coming from a different
> source and then there may be a possibility of unreliable scripts which get
> stuck somewhere and never reach the yield. Maybe there is a way which I am
> not aware of.
> In the meantime I gave it a try to use debug library sethook function with
> coroutines to run multiple scripts and here is a program I tried:

Sandboxing thirdparty scripts has been written a lot about. If the possibility of them hogging the system is an issue, you could use something like the 'corowatch' module does.
But anyway, using debughooks to interrupt cooperative processes is a bad idea anyhow, as it might leave datastructures in an inconsistent state. So you would need some sort of locking, which introduces race conditions and lockups in your code. So basically you end up importing all be bad stuff from pre-emptive scheduling into Lua. 
Btw; corowatch does not force a yield (so doesn't go preemptive), it only kills if it takes too long. So slightly less dangerous, but still data might end up being inconsistent.
Checkout the readme from corowatch on how it works and the caveats of this approach