Storing passwords

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Szymon Gatner
2012/5/22 Tezduyar Lindskog, Umut <[hidden email]>:
> Erik, thank you for your answer.
> Patrik, what I understand from "lua_State is fully thread safe" statement is more than one thread can work on the same lua_State simultaneously? Is this what you meant? If so, what are the synchronization primitives used by lua to support this feature?

lua_State is NOT thread safe. I guess what Eric/Patric meant is that
it is not unsafe to use separate lua_States by different threads
exclusively as there is no hidden shared state between lua_States.
That being said it is possible to make lua_State thread safe by means
of lua_lock() and lua_unlock() (but it is being reported to be very
performance degrading).

Cheers,
Simon

>
> Thanks.
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Patrick Rapin
> Sent: Tuesday, May 22, 2012 10:57 AM
> To: Lua mailing list
> Subject: Re: Is having lua_State per thread safe?
>
>> A lua_State is completly isolated, so they are thread safe. (Has been since
>> Lua 4.0)
>
> Until Lua 5.0, the parser was not completely reentrant.
> So it is more correct to say that a lua_State is fully thread safe
> since Lua 5.1.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Roberto Ierusalimschy
> lua_State is NOT thread safe.

To clarify things:

- Different lua_States created with calls to lua_newstate (or
luaL_newsate) are thread safe, as much as they do not share any mutable
data.

- Different lua_States created with calls to lua_newthread are not
thread safe, as they do share lots of mutable data.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Roberto Ierusalimschy
> To clarify things:
>
> [...]

Sorry for the noise. Without a common meaning for "thread safe", this
discussion is pointless. What seems relevant is this:

- Different lua_States created with calls to lua_newstate (or
luaL_newsate) do not share any mutable data.

- Different lua_States created with calls to lua_newthread do share lots
of mutable data.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Ignacio Burgueño
On Wed, May 23, 2012 at 10:42 AM, Roberto Ierusalimschy
<[hidden email]> wrote:
>
> Sorry for the noise. Without a common meaning for "thread safe", this
> discussion is pointless. What seems relevant is this:
>
> - Different lua_States created with calls to lua_newstate (or
> luaL_newsate) do not share any mutable data.
>

However, some functions from the C runtime do share mutable data. For
instance, gmtime.

Other than that, at work we have many multithreaded applications using
multiple lua_States and they work just fine, and when there is some
bug related to shared state, it's never related to Lua.

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Roberto Ierusalimschy
> > - Different lua_States created with calls to lua_newstate (or
> > luaL_newsate) do not share any mutable data.
> >
>
> However, some functions from the C runtime do share mutable data. For
> instance, gmtime.

Yes :-(  (Well, for this particular case Lua 5.2 uses gmtime_r when
possible. But some other C functions still have problems.)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Ignacio Burgueño
On Thu, May 24, 2012 at 11:27 AM, Roberto Ierusalimschy
<[hidden email]> wrote:
>
> Yes :-(  (Well, for this particular case Lua 5.2 uses gmtime_r when
> possible. But some other C functions still have problems.)
>

Ah, great. Will those kind of fixes be backported into Lua 5.1.x ?

Regards,
Ignacio

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Roberto Ierusalimschy
> On Thu, May 24, 2012 at 11:27 AM, Roberto Ierusalimschy
> <[hidden email]> wrote:
> >
> > Yes :-(  (Well, for this particular case Lua 5.2 uses gmtime_r when
> > possible. But some other C functions still have problems.)
> >
>
> Ah, great. Will those kind of fixes be backported into Lua 5.1.x ?

I do not think so. But I think that with a few defines you should be
able to use the os lib from 5.2 with Lua 5.1.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Luiz Henrique de Figueiredo
> I do not think so. But I think that with a few defines you should be
> able to use the os lib from 5.2 with Lua 5.1.

See also what was done for bi32:
        http://lua-users.org/lists/lua-l/2011-01/msg01039.html

Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Gé Weijers
In reply to this post by Roberto Ierusalimschy
On Thu, May 24, 2012 at 7:27 AM, Roberto Ierusalimschy
<[hidden email]> wrote:

> Yes :-(  (Well, for this particular case Lua 5.2 uses gmtime_r when
> possible. But some other C functions still have problems.)

setlocale, rand and srand come to mind.

So os.setlocale, math.random and math.randomseed should be avoided
after starting threads.

--


Reply | Threaded
Open this post in threaded view
|

Re: Is having lua_State per thread safe?

Philippe Lhoste
In reply to this post by Tezduyar Lindskog, Umut
On 22/05/2012 09:41, Tezduyar Lindskog, Umut wrote something

I see new messages in the Storing passwords thread (in Thunderbird), I go see them and
fall into this hijacking thread which doesn't interest me.
Please, start a new message to write your own thread in the mailing list, don't just reply
to a random message: even if you change subject and all, the id of the original message is
kept and good mailing client will attach it to the original thread.
Beside, it avoids hiding your thread as some people can be interested in your and not in
the original one, and might just mark the original thread as read without even spotting
your...

Thank you.

(And sorry for this slightly off-topic (non-Lua) message.)

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


12