in reply to is a readonly hash thread safe ?

It is thread safe even if you modify the hash, because each thread gets a copy. perlthrtut

Replies are listed 'Best First'.
Re^2: is a readonly hash thread safe ?
by cbrauner (Novice) on Jul 15, 2009 at 09:19 UTC
    but i pass the reference to the hash as a parameter for thread create, so im using the only hash defined in the main block ?

      Even that reference is just a copy. See perlthrtut and/or threads::shared. Perl ithreads are based off the idea of the Win32 fork emulation, which is why every thread gets its own copy of (almost) everything. This likely is the only possible implementation anyway without risking lots of locks like Python has with its much maligned Global Interpreter Lock, as even reading a Perl variable means writing to shared memory (the refcount or integer slots for example) otherwise.

        Perl has also serious problems with LOCKs, using a simple REGEX in several thread instances of the same program causes LOCKs to go HIGH. And this is valid not only for REGEX's. See node
        i pass a hash-reference to the thread, so the thread gets (a copy of) the reference - BUT the data referenced by the hash-reference should be only once in memory ?
      No, each thread gets its own copy. Read the tutorial, it explains the basics.