[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua callback in another thread
- From: Oleg Popov <dev-random@...>
- Date: Sat, 23 Apr 2016 19:09:35 +0300
On Sat, Apr 23, 2016 at 05:18:59PM +0200, Laurent Faillie wrote:
> Hello,
>
> Le 22/04/2016 08:52, Daurnimator a écrit :
> > Infact, sending a packet to a socket *is* actually the best option for
> > this sort of thing. On linux, you have a special fast kernel provided
> > file descriptor type 'eventfd' just for this purpose. In general, you
> > can fall back to using a pipe() or socketpair() and writing a single
> > byte so that the other end polls readable.
>
> My issue is not to signalize anything b/w thread, it's already done
> using eventfb and socket signaling :)
> My issue is to pass a function reference defined in the main thread to
> the newly created one w/o blocking the main one.
And... what are you going to do with that reference? Because references
are just numbers, passing them through sockets is trivial, but they will
be meaningless to another lua_State. If you are going to just pass the
reference eventually back to the main thread, you may handle it as
opaque number. But if you are going to call that function from the
separate thread, you are in trouble. If both threads use the same state,
then you MUST block. And if the state is different, then the only way to
pass objects between states is to copy them, like LuaLanes does. The
copying is difficult, slow and unreliable, and the copy of the function
won't be able to modify the original state (all its upvalues will be
copies of the originals, and _ENV will be that of the new lua_State).