This optimization, as described in PR27658, is safe to perform with Apple pthreads. The implementation of pthread_mutex_destroy does nothing except poison the lock to aid in debugging [1].
If we choose to apply this patch we'll lose some amount of error checking, but I think it's probably worth it given the codegen improvements for global of function local static mutexes.
This same optimization can safely be applied to ~condition_variable, since the destructor doesn't check the return value of the pthread_cond_destroy call. But it looks like we lose more debuggability with condvar than we do with mutex [2][3].
What do you think?
[1] https://opensource.apple.com/source/Libc/Libc-262/pthreads/pthread_mutex.c.auto.html
[2] https://opensource.apple.com/source/Libc/Libc-262/pthreads/pthread_cond.c.auto.html
[3] https://github.com/llvm/llvm-project/blob/master/libcxx/src/condition_variable_destructor.cpp#L40