lua-users home
lua-l archive

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


On 29.06.22 10:38, Oliver wrote:
> On 29.06.22 10:31, Marc H. Balmer wrote:
>> Isn't calling into the same state from different times dangerous, even if you do
>> proper locking?  With proper locking I mean every call of the C API must first
>> obtain a lock, to prevent corrupting the stack, right?
>
> Yes of course. A mtstates object is something like an Java object with
> synchronized method(s).
 Just to clarify, perhaps I was misunderstanding something:

>> proper locking?  With proper locking I mean every call of the C API must
>> first obtain a lock, to prevent corrupting the stack, right?

It is not every call to the C API that needs a lock. It is only the call of the
mtstates object, see methods state:call() and state:tcall() in the
documentation: https://github.com/osch/lua-mtstates#documentation

With this it is IMHO not dangerous to call the state from any thread.
Synchronizing the access and passing the mtstates object id to other threads has
to be done by other solutione, see e.g. the usage of mtmsg in the second
example: https://github.com/osch/lua-mtstates#examples

Best regards,
Oliver