std::mutex
is nonrecursive, and violation of that is UB. So anything is possible in theory(including works as std::recursive_mutex
)), but libc++ seems to work fine , this program outputs
bye
#include <iostream>
#include <mutex>
std::mutex m;
int main() {
std::scoped_lock l1(m);
std::scoped_lock l2(m);
std::cout << "bye" << std::endl;
}
Is this intentional design decision in libc++ or just some accident(for example they could use same logic for mutex and recursive_mutex)?
libstdc++ hangs.
note: I am aware of that people should not rely on UB, so this is not about best practices, I am just curious about obscure implementation details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…