Boost logo

Boost Users :

Subject: [Boost-users] boost::mutex::scoped_lock crashes on OSX
From: David Medine (dmedine_at_[hidden])
Date: 2015-12-15 14:11:38


I am using boost in a python extension and it is having some problems on
OSX. Specifically, I use a mutex of type boost::mutex in both the
constructor and destructor methods. The constructor goes fine and the
destructor crashes. The code works perfectly well on both Windows and Linux.

When my class is building itself, it calls functions like this one a
bunch of times:

void enter_headers_phase(bool phase_locked) {
         if (phase_locked) {
             boost::mutex::scoped_lock lock(phase_mut_);
             headers_to_finish_++;
         }
     }

where phase_mut_ is of type boost::mutex. When debugging in XCode, I see
nice looking members for phase_mut_ at this point in the program:

phase_mut_ (boost::mutex)
     m (pthread_mutex_t)
         __sig (long) 1297437784 1297437784
         __opaque char [56] ""

Later, when I am destroying, I make a nearly identical call as before:

...

{
     boost::mutex::scoped_lock lock(phase_mut_);
     shutdown_ = true;
}

...

but now, my phase_mut_ looks like it has an apparently empty _sig member:

phase_mut_ (boost::mutex)
     m (pthread_mutex_t)
         __sig (long)
         __opaque (char [56]) ""

When we go down the line of the mutex code in boost and finally arrive
at line 62 in boost/thread/pthread/mutex.hpp:

           ret = ::pthread_mutex_lock(m);

I get a segmentation fault: EXC_BAD_ACCESS

It seems like this is becausem->_sig is now empty for some reason, but I
can not determine why (XCode's debugger won't let me 'watch' this
variable) but it should certainly be the case that it doesn't get
touched between the apparently successful constructor routines and now.

This all happens on OSX Yosemite. I am compiling my extension with
LLVM6.1 and I have gnu++0x as the C++ language dialect and libc++ as the
stdlib. I am linking statically to boost 1.57 which I built using this
command:

sudo ./b2 -a cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
toolset=clang link=static link=shared threading=multi install
--prefix=/opt/local --layout-tagged

THX!
-David


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net