How can you get the Linux thread Id of a std::thread()

前端 未结 3 733
说谎
说谎 2021-02-07 12:09

I was playing with std::thread and I was wondering how is it possible to get the thread id of a new std::thread(), I am not talking about std::t

3条回答
  •  走了就别回头了
    2021-02-07 12:36

    Some pthread implementations, e.g. Android 21+, provide

    pid_t pthread_gettid_np(pthread_t);
    

    The implementation may use the internal structure of struct pthread_t to retrieve the native thread id, same as the one returned by gettid() or syscall(SYS_gettid) when called in the context of that thread.

提交回复
热议问题