lua-users home
lua-l archive

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


Hi,

Safely canceling threads Windows is completely impossible. So we can't hope to cancel child threads in a portable way
when one of them chooses to call lua_close. Using pthreads,
it seems this could be accomplished. But if it doesn't work
on Windows, I am not going to bother doing it. We need a
compromise, as you said.

So turn the argument around: exiting the main thread
without cleaning up all other threads is a programmer
error. Document it as such and be done.

The problem is that Lua libraries should shield Lua code
from causing crashes or disrupting the system in any way.

Perhaps what we should do is wait for all threads to exit
naturaly, whenever lua_close is called. This can be
accomplished both on pthreads and Windows.

That way, the user can safely call lua_close and watch his
application wait until all threads choose to leave, or hang
on a dead-lock.

Dead-locks are fine. :) All you need is a couple mutexes to write
one. Adding this possibility to lua_close seems to be an
acceptable comprise.

[Now you know why I'm so fond about non-pre-emptive approaches.]

Dude, it's not like LuaThread is my favourite child. :) I
don't know why people like threads, but there seems to be a
demand for thread support.

You can set __gc for every object. But it will only be called for
userdata objects. The code above only needs a thread counter.

We can use a condition variable and a counter to make sure
we only exit lua_close when all threads are done. Is this a
good solution? I think it is ok.

Regards,
Diego.