<A HREF="#item_lock"><CODE>lock</CODE></A> places a lock on a variable until the lock goes out of scope. If
the variable is locked by another thread, the <A HREF="#item_lock"><CODE>lock</CODE></A> call will block until
it's available. <A HREF="#item_lock"><CODE>lock</CODE></A> is recursive, so multiple calls to <A HREF="#item_lock"><CODE>lock</CODE></A> are
safe--the variable will remain locked until the outermost lock on the
variable goes out of scope.
<P>Locks on variables only affect <A HREF="#item_lock"><CODE>lock</CODE></A> calls--they do <EM>not</EM> affect normal
access to a variable. (Locks on subs are different, and covered in a bit)
If you really, <EM>really</EM> want locks to block access, then go ahead and tie
them to something and manage this yourself. This is done on purpose. While
managing access to variables is a good thing, perl doesn't force you out of
its living room...</P>
<P>If a container object, such as a hash or array, is locked, all the elements
of that container are not locked. For example, if a thread does a <CODE>lock
@a</CODE>, any other thread doing a <A HREF="#item_lock"><CODE>lock($a[12])</CODE></A> won't block.</P>
<P>You may also <A HREF="#item_lock"><CODE>lock</CODE></A> a sub, using <CODE>lock &sub</CODE>. Any calls to that sub from
another thread will block until the lock is released. This behaviour is not
equivalent to declaring the sub with the <CODE>locked</CODE> attribute. The <CODE>locked</CODE>
attribute serializes access to a subroutine, but allows different threads
non-simultaneous access. <CODE>lock &sub</CODE>, on the other hand, will not allow
<EM>any</EM> other thread access for the duration of the lock.</P>
<P>Finally, <A HREF="#item_lock"><CODE>lock</CODE></A> will traverse up references exactly <EM>one</EM> level.
<A HREF="#item_lock"><CODE>lock(\$a)</CODE></A> is equivalent to <A HREF="#item_lock"><CODE>lock($a)</CODE></A>, while <A HREF="#item_lock"><CODE>lock(\\$a)</CODE></A> is not.</P>
<A HREF="#item_join"><CODE>join</CODE></A> waits for a thread to end and returns any values the thread exited
with. <A HREF="#item_join"><CODE>join</CODE></A> will block until the thread has ended, though it won't block
if the thread has already terminated.
<P>If the thread being <A HREF="#item_join"><CODE>join</CODE></A>ed <A HREF="../lib/Pod/perlfunc.html#item_die"><CODE>die</CODE></A>d, the error it died with will be
returned at this time. If you don't want the thread performing the <A HREF="#item_join"><CODE>join</CODE></A>
to die as well, you should either wrap the <A HREF="#item_join"><CODE>join</CODE></A> in an <A HREF="#item_eval"><CODE>eval</CODE></A> or use the
<A HREF="#item_eval"><CODE>eval</CODE></A> thread method instead of <A HREF="#item_join"><CODE>join</CODE></A>.</P>
The <A HREF="#item_eval"><CODE>eval</CODE></A> method wraps an <A HREF="#item_eval"><CODE>eval</CODE></A> around a <A HREF="#item_join"><CODE>join</CODE></A>, and so waits for a
thread to exit, passing along any values the thread might have returned.
Errors, of course, get placed into <CODE>$@</CODE>.