How can I get a unique thread identifier?

Viewed 937

In an attempt to build an "emulated" Reentrant mutex, I need an identifier that is unique to each thread. I can get the current thread via thread::current, but Thread doesn't seem to have anything that could be used (or abused) as an identifier.

For my purposes, I believe the identifier can be reused once a thread exits, although I would be also interested in answers that didn't reuse identifiers as those may be useful in other cases.

3 Answers

but Thread doesn't seem to have anything that could be used (or abused) as an identifier.

This was rectified in Rust 1.19 via Thread::id.

Related