lua-users home
lua-l archive

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


Hi,

> When should I use lua_lock() and lua_unlock() while I write C 
> extention function?
> While I looked over serveral source files, I found some C functions 
> use lua_lock()/lua_unlock() pair, but some functions did not use them.

Lua_lock and lua_unlock are internal to the Lua core. The idea is that when
there are multiple threads accessing the same lua_State concurrently, Lua
uses these macros to sinchronize them. Furthermore, they are not
implemented by the Lua team, but supplied by an external library, such as
LuaThreads.

If you are creating an extention library in C, and wory about concurrent
access, you can use your  own sinchronization functions (or borrow those
provided  by  LuaThreads). Since  access  to  the lua_State  is  already
sinchronized by Lua core (using these  macros), you need only worry with
concurrent access to your C structures.

Regards,
Diego.