Question: In an attempt to build an "emulated" [Reentrant mutex](https://en.wikipedia.org/wiki/Reentrant_mutex), I need an identifier that is unique to each thread. I can get the current thread via [`thread::current`](https://doc.rust-lang.org/std/thread/fn.current.html), but [`Thread`](https://doc.rust-lang.org/std/thread/struct.Thread.html) 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.

Answer: 
Another way is, if you can use `libc`:

```
fn get_thread_id() -> libc::pthread_t {
    unsafe { libc::pthread_self() }
}

```

`pthread_t` will map to the right target per plattform.
> 
> 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`](https://doc.rust-lang.org/std/thread/struct.Thread.html#method.id).