lua-users home
lua-l archive

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


I have an application that spawns several threads, each thread runs a Lua script (each with it's own lua_State). Each script calls some extension functions that abstract a database / communication library that is NOT thread safe. Yesterday I went about adding mutex lock / unlock code around every call to this API from my C code that is called from the scripts. This seemed like the best answer until I got to a function in the API that is basically an iterator. This function calls a callback function to deal with compound data types in the API. This callback function calls Lua library functions, like lua_pushstring(), lua_rawset(), lua_rawget(), etc. There are no lua_error() calls in here. I'm worried about these functions raising errors, longjmp'ing back to the script and leaving my mutex locked, which will deadlock the application.

I thought about writing a wrapper function that I can call from lua_cpcall() but the way I read the documentation the stack that is passed to the C function in lua_cpcall() only has the lightuserdata that was passed. I also need the Lua stack that was passed to the original function.

Thanks

Phil