Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* recursive mutex locks in posix threads
@ 1996-04-25  4:00 Terence Cross
  1996-04-29  4:00 ` Dave Butenhof
  0 siblings, 1 reply; 2+ messages in thread
From: Terence Cross @ 1996-04-25  4:00 UTC (permalink / raw)


Hi,
In the OSF1 (Digital Unix) posix threads package
there is a recursive mutex.
This is not supposed to be used
as the lock for a condition variable
because if recursion is > 1 
then the coniditional wait
will fail to unlock the mutex.
So fast mutexes are suggested.

However, for recursive mutexes,
why did the conditional not simply unlock 
the recursive mutex many times 
until it was free.  Store that number
on the stack.  On return pop the number
and lock it that many times.

rgs,
/Terence Cross.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: recursive mutex locks in posix threads
  1996-04-25  4:00 recursive mutex locks in posix threads Terence Cross
@ 1996-04-29  4:00 ` Dave Butenhof
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Butenhof @ 1996-04-29  4:00 UTC (permalink / raw)



Terence Cross wrote:
> 
> Hi,
> In the OSF1 (Digital Unix) posix threads package
> there is a recursive mutex.
> This is not supposed to be used
> as the lock for a condition variable
> because if recursion is > 1
> then the coniditional wait
> will fail to unlock the mutex.
> So fast mutexes are suggested.
> 
> However, for recursive mutexes,
> why did the conditional not simply unlock
> the recursive mutex many times
> until it was free.  Store that number
> on the stack.  On return pop the number
> and lock it that many times.
> 
> rgs,
> /Terence Cross.

Because if we did so, you might as well not have locked the mutex at
all. Or, to put it another way, if you aren't protecting any data with
the mutex, you should unlock it yourself. If you ARE protecting data
with the mutex, it would be INCORRECT and DANGEROUS for the thread
library to arbitrarily unlock the mutex "all the way".

By the way, it is almost always a bad idea to make any call with a
mutex locked. In about 99% of the cases where it really is necessary
(for example, when calling a library that's not thread-safe), it is
fruitless to use your own mutex to protect it. Some other code may use
a different mutex to protect the same unsafe code -- and if it gets
called concurrently in two different threads, each using a different
mutex, then both callers might as well not have bothered. That's why
DECthreads invented the "global lock" mutex... it is simply a "well
known" public recursive mutex so that it's possible for all code in a
process to agree on a single synchronization mechanism to protect unsafe
code. This was very important when we first released DECthreads for
ULTRIX, OpenVMS 5.5, and the various OSF DCE platforms, none of which
had any support for threads beyond that provided by the thread library.

Now, the global lock (and recursive mutexes in general) have about
outlived their usefulness, and most operating systems have become more
generally "thread aware" and the standard libraries are thread-safe out
of the box.

+-------------------------------------------------------------------+
| Dave Butenhof                       Digital Equipment Corporation |
| butenhof@zko.dec.com                110 Spit Brook Rd, ZKO2-3/Q18 |
| PH 603.881.2218, FAX 603.881.0120   Nashua, NH 03062-2711         |
+----------+     "Better Living Through Concurrency"     +----------+
           +---------------------------------------------+



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-04-29  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-25  4:00 recursive mutex locks in posix threads Terence Cross
1996-04-29  4:00 ` Dave Butenhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox