From owner-freebsd-arch Mon Sep 11 21:25:37 2000 Delivered-To: freebsd-arch@freebsd.org Received: from cs.waikato.ac.nz (taupo.cs.waikato.ac.nz [130.217.248.134]) by hub.freebsd.org (Postfix) with ESMTP id 4DE2937B424; Mon, 11 Sep 2000 21:25:32 -0700 (PDT) Received: (from joerg@localhost) by cs.waikato.ac.nz (8.9.3/8.9.3) id QAA69871; Tue, 12 Sep 2000 16:25:06 +1200 (NZST) (envelope-from joerg) Date: Tue, 12 Sep 2000 16:25:06 +1200 From: Joerg Micheel To: Greg Lehey Cc: Matthew Jacob , Frank Mayhar , John Baldwin , Mark Murray , FreeBSD-arch@freebsd.org, joerg@cs.waikato.ac.nz 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: <20000912162506.C41113@cs.waikato.ac.nz> References: <200009120101.e8C11nN56928@realtime.exit.com> <20000912121105.J88615@wantadilla.lemis.com> <20000912145255.A41113@cs.waikato.ac.nz> <20000912123114.K88615@wantadilla.lemis.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20000912123114.K88615@wantadilla.lemis.com>; from grog@lemis.com on Tue, Sep 12, 2000 at 12:31:14PM +0930 Organization: Dept of Computer Science, University of Waikato, Hamilton, New Zealand Project: WAND - Waikato Applied Network Dynamics, DAG Operating-System: ... powered by FreeBSD Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, Sep 12, 2000 at 12:31:14PM +0930, Greg Lehey wrote: > On Tuesday, 12 September 2000 at 14:52:55 +1200, Joerg Micheel wrote: > > On Tue, Sep 12, 2000 at 12:11:05PM +0930, Greg Lehey wrote: > >> On Monday, 11 September 2000 at 18:02:26 -0700, Matt Jacob wrote: > >>>> Greg Lehey wrote: > >>>>> I've been wondering whether we shouldn't associate mutexes with data > >>>>> structures rather than code. It's possible that it would make it > >>>>> easier to avoid deadlocks. Thoughts? > >>>> > >>>> Speaking as a BSD/OS (and former Unixware) developer: YES! > >>> > >>> Hmm. I would rather have assumed that this is what mutexes are > >>> about. Semaphores gate entry in code. Mutexes provide locking on > >>> data. Simple enough. > >> > >> That's a matter of definition. The big difference I see between a > >> semaphore and a blocking "mutex" is that there's no count associated > >> with the blocking "mutex": it's a degenerate case of a semaphore. > >> > >> At Tandem, we used semaphores exclusively (well, we had a mutex > >> instruction, but it was really interrupt lockout). As far as I can > >> recall, the semaphore counter was always 1, so the effect was > >> identical to the current blocking "mutexes". > > > > I liked the model Sun chose for Solaris. They have mutex', rw_locks, > > condition variables. I don't like semaphores. > > 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. Terms are used interchangeably, so it may not be a difference at all to someone else. I think the point I was making was that the syncronization primitives in Solaris present a consistent view to the programmer, it is very clear what to do to achieve your bit of syncronization (which method to use). I cannot comment on how difficult (and expensive in terms of overhead) it is to use the model. Joerg -- Joerg B. Micheel Email: Waikato Applied Network Dynamics Phone: +64 7 8384794 The University of Waikato, CompScience Fax: +64 7 8585095 Private Bag 3105 Pager: +64 868 38222 Hamilton, New Zealand Plan: TINE and the DAG's To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message