develooper Front page | perl.perl5.porters | Postings from October 1999

Re: perlthread.pod -- First draft of thread docs

Dan Sugalski
October 25, 1999 04:41
Re: perlthread.pod -- First draft of thread docs
Message ID:
At 02:42 PM 10/24/99 -0400, Sam Tregar wrote:
>Some random reactions:
>> When built with the appropriate options, perl provides facilities for
>Which options?  Maybe it should be explicit, or at least link to where
>someone could find out.

I was assuming that the reader would go read the build docs if they cared.
Possiby a bad assumption.

>> async is not exported by default--if you want it, you need to ask for
>> it when you use the Thread module. (If you don't, the code in the
>Should have an example of a use statement that "asks for" async.

I should reword this, but if the reader doesn't know how to do a "use
Thread qw(async);" then they've got bigger problems if they want to use

>> Perl code must never access a variable simultaneously in two or more
>> threads. The only way to safely do this is to lock the variable you're
>> accessing with the lock() function. lock() is advisory, in that it
>> only blocks other locks rather than actual access to a
>> variable. Locks are dynamically scoped, much like the way local works,
>> and stay locked until the lock goes out of scope.
>Maybe I'm a dumbass, but what happens here:
>use vars qw($GLOBVAR);
>sub something_that_locks_globvar {
>	lock($GLOBVAR);
>Does this lock up permanently since the lock() was done already in the
>main scope and then re-tried in a subroutine?  Consider that I may not be
>the only fool that wonders about this...  Is it a candidate for the docs?

Yep. lock()'s reentrant, so that code's ok. If that's at the top level of
your code, then $GLOBVAR will stay locked until the end of the program.

>> The single exception is locking subroutines. If a thread locks a
>> subroutine, perl will prevent any other thread from entering it until
>> the lock is released.
>What is the syntax for locking a subroutine?  lock(\&sub), or what?



----------------------------------------"it's like this"-------------------
Dan Sugalski                            even samurai                           have teddy bears and even
                                        teddy bears get drunk Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About