Re: multithreading in lua 5.1 - changes in luaconf.h

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: multithreading in lua 5.1 - changes in luaconf.h

Mildred Ki'Lya

I think I understand how multithreading works in lua ... thanks to the
wiki page <> (which I
modified a little)

I think locking in lua 5.1 can be done defining this in luaconf.h. Can
someone who knows a little about thar tell me if it is correct or not ?

typedef pthread_mutex_t *pthread_mutex_p;
#define LUAI_EXTRASPACE (sizeof(pthread_mutex_p))
#define lt_back(L)      ((((unsigned char*)L)-sizeof(pthread_mutex_p))
#define lt_mutex(L)     (*((pthread_mutex_p *) lt_back(L)))
#define lua_lock(L)     pthread_mutex_lock(lt_mutex(L))
#define lua_unlock(L)   pthread_mutex_unlock(lt_mutex(L))
#define luai_userstateopen(L)		{ \
	lt_mutex(L) = (pthread_mutex_t *) \
		malloc(pthread_mutex_sizeof()); \
	pthread_mutex_init(lt_mutex(L), NULL); \
#define luai_userstateclose(L)		{ \
	pthread_mutex_destroy(lt_mutex(L)); \
#define luai_userstatethread(L,L1)	{ \
	lt_mutex(L1) = lt_mutex(L); \

Apparently lua 5.1 is better that 5.0 here ... we have different call
when a new state is created with lua_newthread and lua_newstate.

Just a question. Why do not define that in the default distribution
when for example the constant LUA_USE_PTHREAD is defined ? It would be
easier to chose to compile lua with multithreading support or not.


Mildred       <xmpp:[hidden email]> <>
Clef GPG :    <hkp://> ou <>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]