From owner-freebsd-threads@FreeBSD.ORG Fri Feb 13 07:07:16 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 7CA8C16A4CE for ; Fri, 13 Feb 2004 07:07:16 -0800 (PST) Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [204.127.202.56]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4A21043D1F for ; Fri, 13 Feb 2004 07:07:16 -0800 (PST) (envelope-from rodrigc@crodrigues.org) Received: from h00609772adf0.ne.client2.attbi.com ([66.31.45.197]) by comcast.net (sccrmhc12) with ESMTP id <20040213150715012000dhdje>; Fri, 13 Feb 2004 15:07:15 +0000 Received: from h00609772adf0.ne.client2.attbi.com (localhost.crodrigues.org [127.0.0.1])i1DF7Shd079167; Fri, 13 Feb 2004 10:07:28 -0500 (EST) (envelope-from rodrigc@h00609772adf0.ne.client2.attbi.com) Received: (from rodrigc@localhost)i1DF7RVe079166; Fri, 13 Feb 2004 10:07:27 -0500 (EST) (envelope-from rodrigc) Date: Fri, 13 Feb 2004 10:07:27 -0500 From: Craig Rodrigues To: Dag-Erling Sm?rgrav Message-ID: <20040213150727.GA79077@crodrigues.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i cc: threads@freebsd.org Subject: Re: checking lock ownership 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, 13 Feb 2004 15:07:16 -0000 On Fri, Feb 13, 2004 at 12:46:14PM +0100, Dag-Erling Sm?rgrav wrote: > Is there any way, either in POSIX or in FreeBSD, to check if a given > pthread_mutex_t is owned by the current thread? One way is to try unlock it with pthread_mutex_unlock(). If that fails, and errno == EPERM, then the current thread doesn't own the mutex. For a less portable way, look at the source code for _pthread_mutex_unlock() in /usr/src/lib/libpthread/thread/thr_mutex.c -- Craig Rodrigues http://crodrigues.org rodrigc@crodrigues.org