lua-users home
lua-l archive

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


孙世龙 sunshilong <sunshilong369@gmail.com> 于2021年1月28日周四 下午5:17写道:
>
> Hi, list
>
>     In general, the macro named lua_lock is expanded as a
> no-operation(i.e (void)0).
>
>     Here is the related code snippet in Lua-5.3.5:
> /*
> ** macros that are executed whenever program enters the Lua core
> ** ('lua_lock') and leaves the core ('lua_unlock')
> */
> #if !defined(lua_lock)
> #define lua_lock(L) ((void) 0)
> #define lua_unlock(L) ((void) 0)
> #endif
> I wonder when I need to provide a self-defined macro (e.g:
>  #define lua_lock(L) pthread_lock(&mutex))?
>
> I would appreciate it if you could shed some light on this question.
>

If you want to Lua in multi-threads, you'd better create multiple lua
states, one state per one thread.
I'm working on a small lib these days. It implements an N:M scheduler
in lua.  So that you can run M lua states on N OS threads.
All the states use message channels to inter-communicate.

https://github.com/cloudwu/ltask   (Work in process)

--
http://blog.codingnow.com