From owner-freebsd-arch Mon Sep 11 23:32:18 2000 Delivered-To: freebsd-arch@freebsd.org Received: from mercury.Sun.COM (mercury.Sun.COM [192.9.25.1]) by hub.freebsd.org (Postfix) with ESMTP id 6F04237B424; Mon, 11 Sep 2000 23:32:14 -0700 (PDT) Received: from ms-emuc07-01.Germany.Sun.COM ([129.157.128.14]) by mercury.Sun.COM (8.9.3+Sun/8.9.3) with ESMTP id XAA28676; Mon, 11 Sep 2000 23:32:05 -0700 (PDT) Received: from germany.sun.com (hacker [129.157.133.195]) by ms-emuc07-01.Germany.Sun.COM (8.9.3+Sun/8.9.3/ENSMAIL,v1.9) with ESMTP id IAA05431; Tue, 12 Sep 2000 08:32:04 +0200 (MEST) Message-ID: <39BDCDB2.B50BBB52@germany.sun.com> Date: Tue, 12 Sep 2000 08:31:14 +0200 From: Michael Schuster - Sun Germany Organization: Sun Microsystems, Inc. X-Mailer: Mozilla 4.73 [en] (X11; I; SunOS 5.8 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: Joerg Micheel Cc: Greg Lehey , Matthew Jacob , Frank Mayhar , John Baldwin , Mark Murray , 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) References: <200009120101.e8C11nN56928@realtime.exit.com> <20000912121105.J88615@wantadilla.lemis.com> <20000912145255.A41113@cs.waikato.ac.nz> <20000912123114.K88615@wantadilla.lemis.com> <20000912162506.C41113@cs.waikato.ac.nz> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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