Boost logo

Boost :

Subject: Re: [boost] [thread] ~mutex and BOOST_VERIFY
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2013-05-27 05:17:14


On 05/26/2013 11:45 PM, Vicente J. Botet Escriba wrote:
> Le 26/05/13 22:28, Gaetano Mendola a écrit :
>> Hi,
>> I saw that the destructor of ~mutex doesn't have
>> a BOOST_VERIFY anymore on the return value of
>> pthread_mutex_destroy. From SVN logs I can see it was
>> removed in the commit 75882 to manage the EINTR due
>> to some bugged POSIX implementation.
>> I will reintroduce the BOOST_VERIFY like this:
>>
>>
>> ~mutex()
>> {
>> int ret;
>> do
>> {
>> ret = pthread_mutex_destroy(&m);
>> } while (ret == EINTR);
>> BOOST_VERIFY(!ret);
>> }
>>
> What do you want to verify?

Same that the rest of thread library tests. This covers:

1) Mutex is unlocked
2) Use after destroy

>> while we are at it consider the fact that for the
>> same reason ~mutex needs to check for that EINTR
>> return value the same should do timed_mutex.
> yes, this could be done.

Doing a sanity check on this regard:

$ rgrep pthread_mutex_destroy *
pthread/mutex.hpp: ret = pthread_mutex_destroy(&m);
pthread/mutex.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&m));
pthread/mutex.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&m));
pthread/condition_variable.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
pthread/condition_variable.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
pthread/condition_variable_fwd.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
pthread/condition_variable_fwd.hpp: ret = pthread_mutex_destroy(&internal_mutex);
pthread/recursive_mutex.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&m));
pthread/recursive_mutex.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&m));
pthread/recursive_mutex.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&m));
pthread/recursive_mutex.hpp: BOOST_VERIFY(!pthread_mutex_destroy(&m));

Two "problems" arise

1) pthread/mutex.hpp misses the BOOST_VERIFY that was incorrectly removed in the commit for the
   ticket #6200, as you can see in the rest of the code the BOOST_VERIFY is used even in
   pthread/condition_variable_fwd.hpp is issued BOOST_ASSERT(!ret) due the fact that the mutex
   involved is an internal mutex.

2) As the ticket #6200 explains in some bogus POSIX implementation the pthread_mutex_destroy
   can return an EINTR and this case is only covered in pthread/mutex.hpp


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk