Why do functions using std::mutex make a null check of the address of pthread_key_create?
Take this simple function that increments an integer under a lock implemented by std::mutex : #include <mutex> std::mutex m; void inc(int& i) { std::unique_lock<std::mutex> lock(m); i++; } I would expect this (after inlining) to compile in a straightforward way to a call of m.lock() an increment of i and then m.unlock() . Checking the generated assembly for recent versions of gcc and clang , however, we see an extra complication. Taking the gcc version first: inc(int&): mov eax, OFFSET FLAT:__gthrw___pthread_key_create(unsigned int*, void (*)(void*)) test rax, rax je .L2 push rbx mov rbx, rdi