lua-users home
lua-l archive

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


Hi all,

I want give Lua code access to functions implemented by my C program
that can block while they wait for something to be ready, but the
program might also want to do other things while it's waiting, and I'd
rather not make that happen using OS threads. Coroutinies seem like
they're well suited for that task at first, because when I want to run a
Lua function I can just wrap it in a thread that can yield first, and
then the blocking function that the Lua code can call can just yield
something indicating it's waiting, and the thread can be resumed by the
program when desired.

That stops working, though, if the Lua code itself uses coroutines. If
the blocking function is called within a thread other than the one that
the main program has created, then when it yields, control will just go
to another place in the Lua script. I've searched through documentation
and haven't found a way that I can pause a Lua thread and give back
control to the program regardless of the state of that thread, even
though it feels like something like that should be possible.

Am I missing something?