[Numpy-discussion] numpy.random.RandomState threadsafe?
Tue Mar 11 17:08:35 CDT 2008
Okay, thanks! I won't be using the multivariate_normal function in my
code, so this should work fine.
On Tue, Mar 11, 2008 at 3:00 PM, Robert Kern <firstname.lastname@example.org> wrote:
> On Tue, Mar 11, 2008 at 4:18 PM, Hoyt Koepke <email@example.com> wrote:
> > This should be a really quick question. Is a RandomState object
> > thread safe? I'm wanting to use a common RandomState object in a
> > multithreaded program, and I need to know if it's necessary to protect
> > it with a lock (which wouldn't be difficult).
> For nearly all of the methods, yes, they should be. RandomState is
> implemented in C (using Pyrex) and the GIL is acquired before calling
> any C functions. The caveat here is that the methods
> multivariate_normal() calls back out to Python-implemented functions.
> It is possible that the GIL gets released during that call and that
> another thread can pick up execution then. However, even this should
> not be a problem as far as safety goes; no internal state is read or
> changed after the external call.
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
> -- Umberto Eco
> Numpy-discussion mailing list
More information about the Numpy-discussion