Date: Tue, 12 Sep 2000 08:31:14 +0200 From: Michael Schuster - Sun Germany <michael.schuster@germany.sun.com> To: Joerg Micheel <joerg@cs.waikato.ac.nz> Cc: Greg Lehey <grog@lemis.com>, Matthew Jacob <mjacob@feral.com>, Frank Mayhar <frank@exit.com>, John Baldwin <jhb@pike.osd.bsdi.com>, Mark Murray <markm@FreeBSD.ORG>, FreeBSD-arch@FreeBSD.ORG Subject: Re: Mutexes and semaphores (was: cvs commit: src/sys/conf files src/sys/sys random.h src/sys/dev/randomdev hash.c hash.h harvest.c randomdev.c yarrow.c yarro) Message-ID: <39BDCDB2.B50BBB52@germany.sun.com> References: <200009120101.e8C11nN56928@realtime.exit.com> <Pine.LNX.4.21.0009111801490.25916-100000@zeppo.feral.com> <20000912121105.J88615@wantadilla.lemis.com> <20000912145255.A41113@cs.waikato.ac.nz> <20000912123114.K88615@wantadilla.lemis.com> <20000912162506.C41113@cs.waikato.ac.nz>
next in thread | previous in thread | raw e-mail | index | archive | help
Joerg Micheel wrote: > > What's the difference between a mutex and a semaphore? > > None, if it comes to the actual usage and implementation. Usually, > people will use semaphores for locking blocks of code, mutexes for > data structures. Not much of a difference in the end result, but > locking data structures seems more natural to me. well, (in Solaris) there is a difference, mainly in implementation, which affects debugability (is that a correct word? :-) amongs others: Mutexes have ownership whereas semaphores don't. This makes detection of recursive mutex enter (which is not allowed in Solaris, I'm happy to say) and illegal freeing of mutexes trivial. Also, semaphores are multi-valued, and therefore lend themselves to some uses mutexes aren't meant for (I think the dining philosophers were a classical example of that). Performancewise, mutexes are fastest, as they're implemented directly on top of (Sparc's) CAS instruction (in the simple case). > Joerg cheers Michael -- Michael Schuster / Michael.Schuster@sun.com Sun Microsystems GmbH / Sonnenallee 1, D-85551 Heimstetten (+49 89) 46008-2974 / x62974 Recursion, n.: see 'Recursion' 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?39BDCDB2.B50BBB52>