lua-users home
lua-l archive

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

I am sorry to ask a question which has undoubtedly been asked (and answered) multiple times but I still could not find a satisfactory example for how to implement lua_lock correctly for use in a multithreaded-like enviorment.
If I understand this correctly I need to define LUAI_EXTRASPACE to be the sizeof(lock_t) (lock_t being the type of whatever locking mechanism I use) and access lock_t from inside lua_(un)lock using something similar to fromstate/tostate. The initialization and uninitialization should be done with luai_userstateopen and luai_userstateclose respectivly. Also, for each thread that gets created I need to create a new lua_state.

What I don't understand is if LUAI_EXTRASPACE gets allocated in the lua_state struct and not in the global_state struct, doesn't that defeat the whole purpose of a global locking mechanism?
Also it seems to me that I am mixing up here two seperate things? I get the feeling from looking at the code as if there are two seperate issues that I am connecting them, locking on accessing of a luastate and implementing multiple lua states running side by side (even without real OS threads).

I am trying to get a fully fledged lua running inside the linux kernel ( I already have a working version but one of the remaining issues I have before I can go onto bindings is getting the syncronization right. The kernel is a pre-emptive enviorment, meaning it is simmilar to multiple threads accessing the SAME lua_state at the same time. Should implementing the lua_(un)lock be enough? If so where is the correct place to initialize the lock_t?

Sorry for the long winding post, :)
Daniel Brodie