[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 4.1 Alpha and Win32 Multithreading
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 10 Aug 2001 18:17:07 -0300
> First, the Lua 4.1 LUA_USERSTATE #define to allow inclusion of state
> code into the lua_State structure in lstate.h was not sufficient to
> bring this online. No code needs to be added to the lua_State. The
> code to support "proper" multithreading (through this technique anyway)
> has to be in global_State.
I have implemented something along your suggestions using the current
macros. Instead of putting the "lock" stuff in global_State, I created
a new structure for them, and set LUA_USERSTATE to be a pointer to this
structure. When I create the state (with lua_open), I allocate this
structure:
*(mystruct **)L = malloc(sizeof(mystruct));
/* initialize mystruct ... */
When I create new stacks, I copy the pointer from the old
thread to the new one:
NL = lua_newthread(L, 0);
*(mystruct **)NL = *(mystruct **)L;
That way, all threads share the same structure (and we need no extra support
from Lua).
-- Roberto