Date: Tue, 12 Sep 2000 18:45:11 +1200 From: Joerg Micheel <joerg@cs.waikato.ac.nz> To: Michael Schuster - Sun Germany <michael.schuster@germany.sun.com> 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, 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> In-Reply-To: <39BDCDB2.B50BBB52@germany.sun.com>; from michael.schuster@germany.sun.com on Tue, Sep 12, 2000 at 08:31:14AM %2B0200 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> <39BDCDB2.B50BBB52@germany.sun.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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: <joerg@cs.waikato.ac.nz> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000912184511.C70000>