Search code examples
c++c++11stlstdthread

Is std::thread::id unique across processes?


From my experience, it seems that the result of

std::this_thread::get_id()

is unique across process: ids are different from one process to another.

Is this guaranteed by the standard?


Solution

  • std::thread is implemented on top of pthreads in an environment supporting pthreads. So its becomes there is no (portable) guarantee.

    From pthread_self manual:

    Thread IDs are guaranteed to be unique only within a process. A
    thread ID may be reused after a terminated thread has been joined, or a detached thread has terminated.