|
On 30 Dec '05, at 8:51 AM, Dolan, Ryanne Thomas (UMR-Student) wrote:
And in general, one can't take a program written using cooperative threading (which is what Lua coroutines are a form of), drop in an interrupt-driven scheduler, and expect the program to continue working. If threads are interrupted at times they don't expect, their expectations about exclusive access don't hold anymore. For example, a shared variable might be altered by another thread while a thread was interrupted, but it didn't expect this because it hadn't explicitly called yield(). I think the idea of a hook called every N instructions can be used to solve the original problem, but the hook has to be at the C level and can only run native code (i.e. the PalmOS event handling stuff), not Lua. Or rather, if it invokes the Lua VM, it has to be very careful to avoid stepping on any shared state. The most it could do, probably, is to push an event object into a queue somewhere. (Oog, now I'm having flashbacks to when we ported the Mac Java runtime to OS X and had to deal with crazy threading issues with the Carbon libraries...) --Jens |