lua-users home
lua-l archive

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


Hi all,
 
I am creating an application that needs to execute simultaneously multiple (time consuming) lua scripts written by the end-user through the GUI of the application.
The idea is that the main application is used to write, launch and then monitor (completion percentage, etc.) the lua scripts.
 
-> My main problem is to allow users to cancel execution of their running scripts with no memory leaks. I don't need the cancellation to happen "right now" like in a pre-emptive approach but "within a few seconds" would be exactly what I need. I am not interested in the QueueUserAPCEx kernel stuff.
 
What I have already implemented:
- Concurrency in separate OS threads, using the native Win32 API in Windows and pthreads for Unixes
- One luaState per thread
- One running script per luaState
 
Now I need to tackle the "portable cancellation" problem.
 
I have thought of a cancellation system based on a "ThreadMustBeCancelledASAP" flag which would be regularly tested inside the lua user script. But I can't ask the users of my application to call a "isCancelled()" method inside each loop of their scripts, as the cancellation mechanism should be totally internal to my application...
 
So I've thought about some kind of hook inside the Lua runtime core, with some possible variants:
- Test the "ThreadMustBeCancelledASAP" flag when a Garbage Collector occurs (modifying the lua core)
- Test the flag every N lua instructions (with N=1 or 1000, using the debug interface)
- Test the flag at each function call (with the debug interface)
- ...
 
But that implies either to modify the lua runtime core or to use the debug interface, which is maybe not a good idea in a "release" build.
 
What do you think about all that? Is it the right approach? Or am I missing a trivial solution?
 
Thanks a lot if you can give me any advice.



Essayez Live.com, votre nouvelle page d'accueil ! Personnalisez-la en quelques clics pour retrouver tout ce qui vous intéresse au même endroit. au même endroit.