[ale] Perl threads

Fletch fletch at phydeaux.org
Wed Apr 27 14:31:05 EDT 2005


>>>>> "Christopher" == Christopher Fowler <cfowler at outpostsentinel.com> writes:

    Christopher> I looked at perthrtut and there seems to be a lock()
    Christopher> function but no unlock.  I want to lock a variable in
    Christopher> the main program as well as a thread.

If I remember correctly, locks are only active for the enclosing
lexical scope (similar to the lifetime of a lexical variable declared
with my).  The way to lock a smaller chunk of code is to wrap it in
its own block with a lock($whoozits) at the top.  


What you might want to do is use a higher level exclusion mechanism
like Thread::Semaphore instead of the low level lock().


Having said that, unless things have really changed conventional
wisdom has been "don't use threads in Perl".  In general you'll be
better served by forking coprocesses, or using POE and letting it hide
the nastyness.

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list