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

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

Thread Previous | Thread Next
From:
Dan Sugalski
Date:
October 25, 1999 04:41
Subject:
Re: perlthread.pod -- First draft of thread docs
Message ID:
3.0.6.32.19991025065330.00c5c700@tuatha.sidhe.org
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
threads.

>> 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);
>}
>
>lock($GLOBVAR);
>something_that_locks_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?

Yep.


					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