[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: multithreading in lua 5.1 - changes in luaconf.h
- From: Mildred <ml.mildred593@...>
- Date: Tue, 21 Mar 2006 01:09:43 +0100
Hi,
I think I understand how multithreading works in lua ... thanks to the
wiki page <http://lua-users.org/wiki/ThreadsTutorial> (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
--
Mildred <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG : <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]