Open Quuxplusone opened 8 years ago
Bugzilla Link | PR27658 |
Status | CONFIRMED |
Importance | P normal |
Reported by | Eric Fiselier (eric@efcs.ca) |
Reported on | 2016-05-05 13:25:26 -0700 |
Last modified on | 2019-07-07 10:58:05 -0700 |
Version | unspecified |
Hardware | PC All |
CC | compnerd@compnerd.org, hfinkel@anl.gov, llvm-bugs@lists.llvm.org, mclow.lists@gmail.com, nicolasweber@gmx.de |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Here's a survey of what implementations require pthread_mutex_destroy.
FreeBSD
-------
std::mutex requires a destructor on this platform.
On FreeBSD pthread_mutex_t is a typedef for a pointer type, which must be
deallocated using pthread_mutex_destroy. PTHREAD_MUTEX_INITIALIZER is defined
as "NULL", and null mutexs are initialized by the first call to
pthread_mutex_lock.
https://github.com/freebsd/freebsd/blob/e472ae2aec6936a875835e91508cefe7a262a853/lib/libthr/thread/thr_mutex.c#L608
NPTL (GLIBC)
------------
std::mutex should not require a destructor on this platform.
Here pthread_mutex_t is a struct type, which does not hold allocated resources.
The definition of pthread_mutex_destroy seems to be OK to emit.
https://github.com/lattera/glibc/blob/master/nptl/pthread_mutex_destroy.c#L26
Apple
-----
std::mutex should not require a destructor on this platform.
pthread_mutex_t is a struct type that does not contain allocated resources.
Calls to pthread_mutex_t may be omitted.
https://opensource.apple.com/source/Libc/Libc-391.2.3/pthreads/pthread_mutex.c
This also looks safe on Android/Bionic, but I'll check with each relevant vendor before enabling this change on their platform.
https://android.googlesource.com/platform/bionic/+/master/libc/bionic/pthread_mutex.cpp#1008
What about libc++/Windows?
This optimization doesn't work with mingw threads, but it looks safe for Windows native threads seeing as our implementation of libcpp_mutex_destroy is already a NOP [1]. libcpp_condvar_destroy is similarly a NOP on Windows.
I'll commit the relevant changes shortly.
[1] https://github.com/llvm-mirror/libcxx/blob/master/src/support/win32/thread_win32.cpp#L87-L91