Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Sep 2000 19:38:22 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        jhb@FreeBSD.ORG (John Baldwin)
Cc:        eischen@vigrid.com (Daniel Eischen), arch@FreeBSD.ORG
Subject:   Re: Mutexes and semaphores
Message-ID:  <200009251938.MAA29311@usr02.primenet.com>
In-Reply-To: <XFMail.000925100353.jhb@FreeBSD.org> from "John Baldwin" at Sep 25, 2000 10:03:53 AM

next in thread | previous in thread | raw e-mail | index | archive | help
> > But you can't then use a recursive mutex in conjunction with msleep
> > (cv_wait) which forces you to use yet another mutex.  This is fine,
> > but it adds confusion for the programmer.
> 
> This is a problem.  However, for one thing we currently have a
> KASSERT() that panic's if you msleep() on a recursed mutex.  However,
> one could also change msleep() to function like mi_switch() does
> with Giant and have it fully release the lock before sleeping, but
> this probably would not be a Good Thing.

No.  It would not be a good thing.

Consider that I may be sleeping on the acquisition of the third
out of three mutexes.

> > If we are going to support recursive mutex, I think it would be
> > better to add separate calls/macros/data types to support them,
> > so the the mtx mutexes can be simplified.  Calls to mtx_enter
> > with the recursive mutex type wouldn't even compile.
> 
> Err, the recursive nature of the mutexes is very trivial.  It
> doesn't affect the complexity of the mutexes at all.

Yes, it does.  Ownership precludes hand-off.  Recusrion support
implies permission and tacit approval.

A mutex is not recursive.  There are things you simply can not
implement when recursion is permitted for all of your primitives.

The most obvious argument is still that a mutex is intended to
protect data, not code.  Recursion is only required if the mutex
is actually protecting reentrancy of code, not access to data.

How would you implement vop_lookup() using a recusring mutex;
considering the ownership handoff which must occur?  You will
need a non-recursing mutex to protect yout recursing mutex
during the process of changing the owner (consider an ihash
reclaim during lookup, or ownership of a vnode mutex on a vnode
retrieved from the DNLC).


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009251938.MAA29311>