lua-users home
lua-l archive

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





Le Dimanche 7 juin 2015 1h38, Nagaev Boris <bnagaev@gmail.com> a écrit :


On Sat, Jun 6, 2015 at 10:55 PM, Laurent FAILLIE <l_faillie@yahoo.com> wrote:

> Why to spawn new OS thread per incoming message?

Sorry, I wasn't clean : not per incoming message.
The main program and the incoming loop are running in separate thread meaning msg handling is done in background whatever the main program is doing : the old good preemptive mode. But messages callbacks are running within this second thread.

> See also luajit.io [1], it looks like nginx rewritten in LuaJIT.

I will, thanks for the link.

> lua_newthread creates Lua thread (aka coroutine, green thread).

Cooperative multitasking and not preemptive multi-tasking, right ?

> Lua thread is a part of Lua state so it can access global variables.
> Remember that Lua state itself is not thread-safe, that is why
> multiple Lua threads started from same Lua state must not be touched
> by multiple OS threads at the same moment.

So it's not what I'm looking for.

> luaL_newstate / lua_newstate create independent Lua state. Global
> variables are not inherited. Nothing is inherited. They are completely
> independent!

So my "this morning" idea : I'll use lua_newstate() so my Lua part will be thread safe (not the same Lua_state at all). This will prevent as well callback to call global stuffs. And I'll create some C helpers to do IPC.

Thanks for your patience and clear explanation

Laurent