Lua 3.1 in multithreaded win32 enviroment (fwd)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua 3.1 in multithreaded win32 enviroment (fwd)

Dan Marks
> Have anyone worked with Lua 3.1 in a win32 multithreaded enviroment. I was trying
> to have a lua_state for each thread (By using the __declspec(thread) on
> lua_state) but it seems to crash on me. Without anything I can get Lua to run
> great in two thread but with a common Global scope - I want the global variables
> to be thread specific (Actually trigger-code section specific). I'm compiling
> with Watcom 11 - have not have time to try with VC++ 5.0 yet.
> 

I've actually have this working great.  All I needed to do was declare
the lua_state variable a thread local variable, and as long as each thread
only accesses its own instance things are fine.  I did this with VC++ 
not Watcom.  We have gotten multiple Lua instances to run in separate
threads for at least two or three of them running simulatenously.  Perhaps
you should make sure your ANSI calls malloc() and free() are thread safe,
as well as any stdio.h library calls you use.

BTW, has any work been done on getting Lua to use a pool-type allocator
rather than malloc/free?  This would help for limited memory situations
and running on embedded systems.

Dan

Dan Marks
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Lua 3.1 in multithreaded win32 enviroment (fwd)

Erik Hougaard
Dan Marks wrote:
> threads for at least two or three of them running simulatenously.  Perhaps
> you should make sure your ANSI calls malloc() and free() are thread safe,
> as well as any stdio.h library calls you use.

Have you made any modification to thoose functions - wanna share ?

>BTW, has any work been done on getting Lua to use a pool-type allocator
>rather than malloc/free?  This would help for limited memory situations
>and running on embedded systems.

Not directly releated, but I looking into multiply heaps (Like the
MPHEAP example from the win32 API) for optimizing Lua memory use on
multi-processors and multithreading.


Erik