<div dir="ltr">Currently recursive_mutex::~recursive_mutex() asserts if pthread_mutex_destroy fails, and one of the reasons this can fail is if the mutex is locked by another thread. This leads to the assert being triggered in the following sample program:<div>
<br></div><div><div>#include <mutex></div><div>#include <stdlib.h></div><div>#include <stdio.h></div><div><br></div><div>std::recursive_mutex& getMutex() {</div><div> static std::recursive_mutex mutex;</div>
<div> return mutex;</div><div>}</div><div><br></div><div>void* ThreadFunc(void* arg) {</div><div> std::lock_guard<std::recursive_mutex> Lock(getMutex());</div><div> exit(1);</div><div> return nullptr;</div><div>
}</div><div><br></div><div><br></div><div>int main(int argc, char** argv) {</div><div> pthread_t thread;</div><div> pthread_attr_t attr;</div><div><br></div><div> pthread_attr_init(&attr);</div><div> pthread_create(&thread, &attr, ThreadFunc, nullptr);</div>
</div><div> pthread_join(thread, nullptr);</div><div><br></div><div> return 0;</div><div>}</div><div><br></div><div><br></div><div>Is this assertion bogus? I'm trying to replace a mutex in LLVM with recursive_mutex but am blocked by this because the builder on FreeBSD actually aborts here due to the assertion. </div>
<div><br></div><div>What's the best way to go about resolving this? Even if we decide that the assertion should be removed, it's not going to stop the builders from failing every time until they get a new build of libc++, and I don't think (but maybe I'm wrong?) the builders build libc++, but rather just use the one that's already installed.</div>
<div><br></div><div>Thoughts?</div></div>