From owner-freebsd-threads@FreeBSD.ORG Fri Feb 20 07:02:03 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C3F1E16A4CE for ; Fri, 20 Feb 2004 07:02:03 -0800 (PST) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 826AF43D2F for ; Fri, 20 Feb 2004 07:02:03 -0800 (PST) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.10/8.12.1) with ESMTP id i1KF21SQ002727; Fri, 20 Feb 2004 10:02:01 -0500 (EST) Date: Fri, 20 Feb 2004 10:02:01 -0500 (EST) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?= In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE cc: threads@freebsd.org Subject: Re: cross-thread locking X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Feb 2004 15:02:03 -0000 On Fri, 20 Feb 2004, Dag-Erling [iso-8859-1] Sm=F8rgrav wrote: > - What happens when a thread locks a mutex and then starts another > thread? Does the new thread in any way inherit the lock, or will it > have to acquire its own? No, it doesn't inherit any locks. > - What about spin locks? Are there any semantic differences between > mutexes and spin locks in POSIX, or are spin locks simply mutexes > that spin instead of sleeping? POSIX differentiates between spinlocks and mutexes, and that is why there is a pthread_spinlock_t instead of using pthread_mutex_t for both lock operations. I believe the implementation is allowed to spin indefinitely or schedule another thread if the lock is busy. I can't find a rationale for spinlocks; I _thought_ there was one in some draft of the spec that I had read. I wouldn't really advocate using spinlocks due to possible priority inversion problems and wasting cycles. --=20 Dan Eischen