[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: When must I provide a self-defined lua_lock macro(e.g: #define lua_lock(L) pthread_lock(&mutex))?
- From: 孙世龙 sunshilong <sunshilong369@...>
- Date: Thu, 28 Jan 2021 19:27:55 +0800
>But providing lua_lock you will get a multithreaded Lua very difficult to use, there will be deadlock problems difficult to solve.
Did you ever encounter deadlock problems when using vanilla Lua?
Best regards
sunshilong
On Thu, Jan 28, 2021 at 6:22 PM Victor Bombi <sonoro@telefonica.net> wrote:
>
>
> > On January 28, 2021 at 10:17 AM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> >
> >
> > 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.
> >
> > Best regards
>
> Lua is not multithread ready unless you define lua_lock. But providing lua_lock you will get a multithreaded Lua very difficult to use, there will be deadlock problems difficult to solve.
> The best way to use Lua in a multithread environment is to create a different lua_State in each thread and let all different lua_States to inter-communicate. I would recomend using LuaLanes for achieving this althought there are a lot of alternatives.
>
> Best
> Victor Bombí
> > sunshilong