0

For a worker thread I am using the following "simple" logic

void App::RenderThreadFct()
{
    while(m_TerminateRenderThread == false){
        ...
    }
}

with m_TerminateRenderThread being a volatile variable.
What confuses me a little was digging through the fancy C++ documentation for all the new features for multithreading like std::future, std::promise and god knows what else.
While all these for sure have their legitimation, they look total overkill to me to tackle such a "simple" problem.
But Internet searches totally confused me as they gave me solely solutions of that kind for doing it "properly" in C++.
Am I missing something and is there any reason why I should not check in a worker thread for a simple termination flag (which of course must be volatile)?

  • After the close and to save you more searching - use `std::atomic m_TerminateRenderThread;` See also https://en.cppreference.com/w/cpp/atomic/atomic – Richard Critten Feb 07 '21 at 14:59
  • Oops, yes, now that you point me to it: std::atomic was hiding in plain sight and I did not see it. Thanks! – Gregor Grunz Feb 07 '21 at 15:23

0 Answers0