On Thu, 20 Nov 2003, Stefan Bergler wrote:

> It is sufficient to have ONE lock within ONE thread, to own the shared
> variable as long as this lock is within the scope of the thread. This
> lock is kind of inheritet by any called sub function and it does not
> make a difference if the subfunction does an additional lock or not. (I
> would rather say, the subfunctions should not do additional locking if
> the shared variable is already locked.)

It makes a difference to the design, if the subfunctions are may be called
independently:

  my $m : shared;
  sub do_this  { lock($m); $m++; }
  sub do_that  { lock($m); $m *= 2; do_this(); }

I might call "do_this" myself, or implicitly from within "do_that", and it
must hold the lock in either case.  (Along those lines, X/Open offers
PTHREAD_MUTEX_RECURSIVE and win32 has re-enterable CriticalSections, I
believe.)

Regards,
Mike
-- 
Michael J. Pomraning
[EMAIL PROTECTED]
http://pilcrow.madison.wi.us

Reply via email to