develooper Front page | perl.perl5.porters | Postings from March 2000

Re: What's left to do? [LONG]

Thread Previous | Thread Next
From:
Dan Sugalski
Date:
March 22, 2000 11:03
Subject:
Re: What's left to do? [LONG]
Message ID:
4.3.0.20000322134719.01d307c0@24.8.96.48
At 01:23 PM 3/22/00 -0500, Sam Tregar wrote:
>On Wed, 22 Mar 2000, Dan Sugalski wrote:
>
> > >My current understanding is that in a threaded program all code that
> > >accesses global data need to use some kind of explicit locking.  Thus, any
> > >module that accesses global data of any kind is not thread safe and needs
> > >modification to be thread safe.  Is this accurate?
> >
> > Yup, that's accurate. Global data, in this case, isn't just package
> > variables, but any variable that might be visible, including lexicals and
> > things inside objects and such.
>
>So, essentially, "testing" for thread safety boils down to a process of
>visual inspection.  Correct?

And some stress-testing looking for geeked up results and core dumps, yep.

>As far as figuring out what's safe and what's not, could you explain how
>lexicals can be unsafe?  Are there global variables that *are* safe, like
>$_ and @_ for example, or are they all in need of locks?

Most of the perl special variables are safe. Pretty much everything else 
could be seen by multiple threads. Visible data is:

1) Package variables
2) Lexicals that are in scope for the code being executed in the thread
3) Any variable explicitly put someplace the thread can see. (i.e. passed 
as a parameter, stuck in a queue, stuck in an array or hash in scope for 
the thread code)

>RTFM?  Which one?

Well, there's the docs for Thread and the various Thread modules, and 
perlthrtut, but that's about it. Past that you need to go source diving.

					Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan@sidhe.org                         have teddy bears and even
                                      teddy bears get drunk


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About