Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Mar 2012 08:33:07 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        David Xu <davidxu@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r233103 - head/lib/libthr/thread
Message-ID:  <201203190833.08153.jhb@freebsd.org>
In-Reply-To: <201203180022.q2I0MThr093557@svn.freebsd.org>
References:  <201203180022.q2I0MThr093557@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Saturday, March 17, 2012 8:22:29 pm David Xu wrote:
> Author: davidxu
> Date: Sun Mar 18 00:22:29 2012
> New Revision: 233103
> URL: http://svn.freebsd.org/changeset/base/233103
> 
> Log:
>   Some software think a mutex can be destroyed after it owned it, for
>   example, it uses a serialization point like following:
>   	pthread_mutex_lock(&mutex);
>   	pthread_mutex_unlock(&mutex);
>   	pthread_mutex_destroy(&muetx);
>   They think a previous lock holder should have already left the mutex and
>   is no longer referencing it, so they destroy it. To be maximum compatible
>   with such code, we use IA64 version to unlock the mutex in kernel, remove
>   the two steps unlocking code.

But this means they destroy the lock while another thread holds it?  That 
seems wrong.  It's one thing if they know that no other thread has a reference 
to the lock (e.g. it's in a refcounted object and the current thread just 
dropped the reference count to zero).  However, in that case no other thread 
can unlock it after this thread destroys it.  Code that does this seems very 
buggy, since if the address can be unmapped it can also be remapped and 
assigned to another lock, etc., so you could have a thread try to unlock a 
lock it doesn't hold.

Also, being able to safely inline the common case for pthread locks is a very 
useful optimization and one we should pursue IMO.

-- 
John Baldwin



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