Replace ReentrantMutex by a futex-based one on Linux. by m-ou-se · Pull Request #95727 · rust-lang/rust (original) (raw)

That might not work if a thread doesn't unlock and then exits. Another new thread may then suddenly acquire the lock if the allocator happens to return the same pointer.

That should work out fine, as the old thread doesn't exist anymore, it's fine for the new thread to take over ownership of the lock.

There is a ThreadId type you can use instead.

I am aware, but the ThreadId type is 64-bit, which is problematic on some 32-bit platforms.