From owner-freebsd-arch Mon Sep 11 23:45:29 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 F3D9D37B423; Mon, 11 Sep 2000 23:45:24 -0700 (PDT) Received: (from joerg@localhost) by cs.waikato.ac.nz (8.9.3/8.9.3) id SAA70493; Tue, 12 Sep 2000 18:45:11 +1200 (NZST) (envelope-from joerg) Date: Tue, 12 Sep 2000 18:45:11 +1200 From: Joerg Micheel To: Michael Schuster - Sun Germany Cc: Greg Lehey , 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: <20000912184511.C70000@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> <20000912162506.C41113@cs.waikato.ac.nz> <39BDCDB2.B50BBB52@germany.sun.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <39BDCDB2.B50BBB52@germany.sun.com>; from michael.schuster@germany.sun.com on Tue, Sep 12, 2000 at 08:31:14AM +0200 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 08:31:14AM +0200, Michael Schuster - Sun Germany wrote: > 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). Ok, a semaphore could have an initial value of 2 and being entered by 2 threads before blocking would occur. This really is a academic case, you can implement it with more essential mechanisms - mutexes. Your definition of a semaphore seems to suggest an implementation detail. For a mutex, it is only important if it is held by someone or not. For a semaphore there is additional information on who holds it. It would allow recursive enter of the same lock already being held - something useful at times for getting the locking code right (with multiple locks and data dependencies). It smells somewhat of a bug - harder to implement and debug and perhaps unnecessary. I think the goal is to define the minimal set of primitives and get it right - fast, efficient, cheap, whatever. > Performancewise, mutexes are fastest, as they're implemented directly on > top of (Sparc's) CAS instruction (in the simple case). Exactly. 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