lua-users home
lua-l archive

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


Hi all,

I've been recently trying to get winapi to do Real Things, and I'm
hitting those little random crashes which suggest that multithreading
in Lua is not as simple as I naively thought.

Current design is e.g. to have a thread waiting for i/o, and then
dispatch the callback when a read() returns, ensuring that only one
callback can be active at a time using mutexes.  (Ditto for timers and
so forth).  One obvious problem is that we could be running Lua code
in the main thread anyway, which suggests that the mutex should only
unlocked when we are sleeping or otherwise waiting on some event.  But
the callbacks still happen on _another thread_, so I wonder if this
isn't the real problem.

Can such a design be made truly solid? I remember reading that Mike
Pall reckoned that coroutines created from the C side should work
fine.

(My apologies for the vagueness, but multithreading is not my native language)

steve d.