Parallel processes: multi-core, same CPU?

153 views
Skip to first unread message

H J

unread,
Jun 10, 2026, 8:21:38 PMJun 10
to lu...@googlegroups.com
Leveraging fast shared memory access on the same (dual-core) CPU, I want to spawn two threads on each core of the same CPU. Is this possible with luajit? (I've been looking into `effil` but don't see how you can direct the task to a specific core...).
-- Henk 

TopchetoEU

unread,
Jun 14, 2026, 10:22:38 AMJun 14
to lu...@googlegroups.com
This is a known limitation with lua - you can't run two lua threads (under the same lua_State) in parallel. AFAIK lua allows you to define some locking primitives, but they only serve to lock the current lua_State while lua code is executing, so in effect, only one lua thread is really executing at a time.

Your best bet is to create one lua_State per OS thread and device some kind of communication protocol between different lua states (since two states cannot share tables).

P.S.: Once upon a time I tried to rewrite the lua engine with parallelism in mind, but it was so hopefully slow I won't even dignify it with a link here.

On Thursday, June 11th, 2026 at 3:21 AM, H J <hjans...@gmail.com> wrote:

> Leveraging fast shared memory access on the same (dual-core) CPU, I want to spawn two threads on each core of the same CPU. Is this possible with luajit? (I've been looking into `effil` but don't see how you can direct the task to a specific core...).-- Henk
>
> --
> You received this message because you are subscribed to the Google Groups "lua-l" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/lua-l/CAJrhCY%2BwUejTLNbMf2WKauy2%3D%2B8%2BtVA-Jyoq14ABG96imjYH%2Bw%40mail.gmail.com.

Benoit Germain

unread,
Jun 14, 2026, 12:11:42 PMJun 14
to lu...@googlegroups.com
Le dim. 14 juin 2026 à 16:22, 'TopchetoEU' via lua-l <lu...@googlegroups.com> a écrit :
This is a known limitation with lua - you can't run two lua threads (under the same lua_State) in parallel. AFAIK lua allows you to define some locking primitives, but they only serve to lock the current lua_State while lua code is executing, so in effect, only one lua thread is really executing at a time.

Your best bet is to create one lua_State per OS thread and device some kind of communication protocol between different lua states (since two states cannot share tables).

Shameless plug: one option is https://github.com/LuaLanes/lanes (there are others, but they can publicize themselves :-)).

--
Benoit.

Norman Ramsey

unread,
Jun 17, 2026, 6:30:04 PMJun 17
to lu...@googlegroups.com
> > This is a known limitation with lua - you can't run two lua threads (under
> > the same lua_State) in parallel...
>
> Shameless plug: one option is https://github.com/LuaLanes/lanes (there are
> others, but they can publicize themselves :-)).

I have used Lua Lanes and gotten excellent speedups.


Norman

H J

unread,
Jun 17, 2026, 8:12:22 PMJun 17
to lua-l
Thanks for your suggestions.
AFAIK there are two candidates for parallel processing: `lanes` and (the newer) `effil`; they look similar to me but I have only experience with `effil`. Has anyone experience with both, and can share their relative pros and cons?
-- Henk


云风 Cloud Wu

unread,
Jun 17, 2026, 9:22:40 PMJun 17
to lu...@googlegroups.com
H J <hjans...@gmail.com> 于2026年6月18日周四 08:12写道:
>
> Thanks for your suggestions.
> AFAIK there are two candidates for parallel processing: `lanes` and (the newer) `effil`; they look similar to me but I have only experience with `effil`. Has anyone experience with both, and can share their relative pros and cons?

I'd like to recommend my Lua task library ltask to the Lua community.
https://github.com/cloudwu/ltask

It is a flexible library that implements an n:m scheduler to run M Lua
states on N OS threads, and the lua services communicate via message
channels.

Marc Balmer

unread,
Jun 18, 2026, 2:53:56 AMJun 18
to lu...@googlegroups.com
We us this scheme in production a lot, e.g. for https://trx-control.msys.ch

You find another approach at https://github.com/arcapos/mqlua where we
can create Lua states in separate POSIX threads and have them
communicate using ZeroMQ.


Reply all
Reply to author
Forward
0 new messages