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
This topic seems to be discussed quite a few times here, like in this topic:
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.
You could save it while this_thread
is still the original thread:
std::thread::id main_thread_id;
int main() {
main_thread_id = std::this_thread::get_id(); // gotcha!
/* go on */
}