`<mutex>`: `mutex` and `condition_variable` could provide `native_handle()` again
#3770 is removing the useless implementations of native_handle() in mutex (et al.) and condition_variable.
We could restore them to return void* pointing to the underlying SRWLOCK and CONDITION_VARIABLE, now that we know that this machinery is always used. (It would be permanently "punching through" to the DLL/LIB's representation.)
Remember to restore the minimal test coverage of native_handle() in tests/std/tests/Dev11_1150223_shared_mutex/test.cpp.
I'm mildly against due to "permanently "punching through" to the DLL/LIB's representation", and also due to not seeing an useful application of such native_handle()
I'm mildly against due to "permanently "punching through" to the DLL/LIB's representation", and also due to not seeing an useful application of such
native_handle()
+1 "mildly against". The design intent of native_handle is to facilitate gradual migration of code using pthreads to standard library threading facilities. I do not think that's a useful feature in 2023. I do think it's a mistake to tie our hands by exposing implementation details in the interface of Standard Library types.
@StephanTLavavej should the docs for native_handle() here be updated to note that it has been removed? I was just attempting an upgrade of a large code base from v142 to v143 and noticed this compilation error in a debug wrapper type that we have for std::mutex and std::recursive_mutex.
@steji113 thanks for the reminder. I've poked our team's doc person about updating docs for this change.
This impacted me today. I'm trying to convert code that uses the https://github.com/DOCGroup/ACE_TAO mutexes, which wrap the underlying primitives in a similar way to https://github.com/microsoft/STL/blob/main/stl/inc/mutex
The code consuming these ACE library mutexes use the underlying native handles to inspect things like thread ownership and lock counts for additional debugging capabilities.
Since the standardized mutexes lack this information, the only way to convert this existing code to standard mutexes without stripping out the existing debugging code would be to play funky games with casting the std::mutex to _Mtx_internal_imp_t.
The libstdc++ implementation provides the native handle, and can be converted to use std::mutexes easily, but the Microsoft STL doesn't.