lua-users home
lua-l archive

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


I have a multi-threaded application that I want to embed Lua into. Can you tell me if my current plan will work as I expect?

 

My application has more than one thread (typically one thread plus two more per CPU core). Each thread create some number of fibers (effectively a lightweight thread stack). By design each thread is completely independent of every other thread.

 

I will create a separate Lua interpreter for each thread. Each fiber will have its own Lua thread. When a fiber has time to run, it will execute Lua code until the code finishes or a co-routine in the Lua code yields.

 

My assumptions are:

·         Each Lua interpreter is completely independent of every other interpreter. I could have as many as I want (memory permitting).

·         Each Lua thread shares global state with all other threads in the creating interpreter unless I do something to prevent that.

 

Do I understand this correctly? Should the above solution work?

 

Having a single thread for running all Lua code on a single interpreter will not scale to meet my needs unfortunately.  Aside from the two mentioned approaches to this use case, are there any other known ways to handle this use case with Lua?

 

Marcus