Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2024-04-26 17:24:59


Vinícius dos Santos Oliveira wrote:
> Em sex., 26 de abr. de 2024 às 13:51, David Bien via Boost
> <boost_at_[hidden]> escreveu:
> > Under Linux when BOOST_THREAD_HAS_EINTR_BUG is defined we
> SIGABRT at this:
> >
> > ~mutex()
> > {
> > BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
> > }

What is the return value of pthread_mutex_destroy here?

> How is the code for BOOST_THREAD_HAS_NO_EINTR_BUG? Are UNIX signals
> being involved?

It's used here: https://github.com/boostorg/thread/blob/aec18d337f41d8e3081ee65f5cf3b5090179ab0e/include/boost/thread/pthread/pthread_helpers.hpp#L17

Basically, the relevant code is:

#ifdef BOOST_THREAD_HAS_EINTR_BUG

    BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
    int pthread_mutex_destroy(pthread_mutex_t* m)
    {
      int ret;
      do
      {
          ret = ::pthread_mutex_destroy(m);
      } while (ret == EINTR);
      return ret;
    }

#else

    BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS
    int pthread_mutex_destroy(pthread_mutex_t* m)
    {
      return ::pthread_mutex_destroy(m);
    }

#endif

The only scenario in which the former can return nonzero when the latter doesn't
would be if it returns EINTR, and then tries to destroy the mutex again, and then
get EINVAL because the mutex has already been destroyed.

But this doesn't make sense because in this case the other function would have
returned EINTR, which is also nonzero, so it should also fail the VERIFY.

So I'm at a loss here. More printf debugging (printing the return values in both
cases) is needed.


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