std::thread detect main thread

Viewed 3454

is thre any relieable way in c++11 to detect if the current thread is the main thread? Or would I have to manually save the main threads thread id with std::this_thread::get_id() and then have a routine like this:

bool isMainThread()
{
    return theMainThreadIdISavedOnProgramStart == std::this_thread::get_id();
}

Is there a common way to do this? Would the above solution work?

Thanks

1 Answers
Related