Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Feb 2004 10:07:27 -0500
From:      Craig Rodrigues <rodrigc@crodrigues.org>
To:        Dag-Erling Sm?rgrav <des@des.no>
Cc:        threads@freebsd.org
Subject:   Re: checking lock ownership
Message-ID:  <20040213150727.GA79077@crodrigues.org>
In-Reply-To: <xzp1xozp5h5.fsf@dwp.des.no>
References:  <xzp1xozp5h5.fsf@dwp.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040213150727.GA79077>