[v3] use NSDMI in C++11 mutex types

Jonathan Wakely jwakely.gcc@gmail.com
Wed Oct 26 20:37:00 GMT 2011


On 26 October 2011 21:33, Jonathan Wakely wrote:
> On 26 October 2011 19:57, François Dumont wrote:
>>
>>    This is surely a naive remark as it is already the way the code is
>> written and I haven't taken time to check the code in detail but there is
>> something that surprised me in this patch. The __GTHREAD_MUTEX_INIT has also
>> an impact on the definition of the destructor. Shouldn't the
>> __gthread_mutex_destroy for __mutex_base or the _S_destroy for
>> __recursive_mutex_base be called no matter how the _M_mutex has been created
>> ?
>
> "You do not need to destroy a mutex that was statically initialized
> using the PTHREAD_INITIALIZER_MACRO."
> p51, "Programming with POSIX Threads", Butenhof, 1997
>
> If it's good enough for Butenhof it's good enough for me :)
>
> For non-POSIX platforms that require an explicit destroy call, the
> gthreads layer should not define __GTHREAD_MUTEX_INIT, which will
> force us to use the init/destroy functions.
>

Also, on one platform calling pthread_mutex_destroy after using the
INIT macro caused an error:
http://lists.freebsd.org/pipermail/freebsd-threads/2010-September/004913.html
That's a bug, but the fact it was implemented that way is persuasive
that one is not expected to explicitly destroy a statically
initialized mutex.



More information about the Libstdc++ mailing list