[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Passing function b/w mutithreaded states
- From: Andrew Gierth <andrew@...>
- Date: Mon, 09 Apr 2018 20:36:11 +0100
>>>>> "Laurent" == Laurent FAILLIE <l_faillie@yahoo.com> writes:
Laurent> So, what should I do to correctly call a function in another
Laurent> thread ?
Dump the function to a bytecode string and load the string in the other
state.
You can't safely do it any other way, because each "main" state has its
own independent garbage collection, and can't know whether any of its
objects are referenced by other main states. Even if you worked around
that by holding references to everything, you'd fall foul of memory
synchronization issues, string interning issues, and all sorts of other
breakage (some of which you mentioned in your message).
If you turn on API checks, you'll notice that lua_xmove will abort if
you try and move values between independent states; this operation is
forbidden. The only way to communicate values between independent states
is to serialize them in some form.
(cqueues has an example, you might look at that)
--
Andrew.