[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strange crash when calling lua_call()
- From: Kevin Martin <kev82@...>
- Date: Mon, 8 Apr 2013 08:15:14 +0100
On 8 Apr 2013, at 07:49, Satz Klauer wrote:
> Beside of that the user can define a callback function within
> LUA-script that can be called out of the application asynchronously,
> means out of an own thread.
How are you synchronising access to the state, only one os thread can use the state at a time. So, if you're running a script in one thread, you can't do anything else in another thread.
> Here the C-code fetches the function by
> calling lua_getfield(), builds up the parameters of this function to
> be called via lua_pushxxx() and then calls lua_call()
lua_call longjmps on error. If you're only calling lua_call, where is the setjmp? Perhaps you should be using lua_pcall instead.
> My first idea: it is a threading/race condition problem, so I
> encapsulated all LUA-to-C-functions and the C-to-LUA-callback with one
> mutex. So now calling form LUA to my C-code and constructing the call
> from my C-code back to LUA is done exclusively, none of these calls
> can overlap anymore.
This is what I don't understand. You have protected the Lua-C calls, but these calls must be called from somewhere, is that somewhere protected by the same mutex, if not then the state can be accessed by both that thread, and your mutex protected threads.
Thanks,
Kevin
----------------------------
* It is possible for multiple threads to work with the same state simultaneously using lua_lock/lua_unlock, but I don't understand that.