id of “main” thread in c++

前端 未结 2 975
灰色年华
灰色年华 2020-12-17 23:09

Is there a way in c++ to get the id of the \"main\" program thread?

I see that std::this_thread::get_id() gets the id of the currently executing thread

2条回答
  •  北海茫月
    2020-12-17 23:47

    This topic seems to be discussed quite a few times here, like in this topic:

    • Getting a handle to the process main thread

    You can find some solutions, but I'd just think the other way round... When starting the new threads, just supply the id of the main thread to them, and store that in a field in the other threads. If that is not going to change throughout the threads' life, you're good to go, you can reference the "main" thread by those handles.

提交回复
热议问题