how can I tell if pthread_self is the main (first) thread in the process?

前端 未结 3 1892
猫巷女王i
猫巷女王i 2021-01-11 16:59

background: I\'m working on a logging library that is used by many programs.
I\'m assigning a human-readable name for each thread, the main thread should get \"main\", b

3条回答
  •  执念已碎
    2021-01-11 17:19

    Call pthread_self() from main() and record the result. Compare future calls to pthread_self() to your stored value to know if you're on the main thread.

提交回复
热议问题