boost resume thread on mutex unlock

101 views Asked by At

In my application I have a Calculator Thread and a Main_Thread. Both work on the same data. The calculator thread makes precalculations and the main thread visualized the generated data. To prevent that they change and read the data at the same time, I use boost mutex for my critical sections.

boost::recursive_mutex m_guard_calculation;

Calculator Thread:

m_guard_calculation.lock();
// do hard calculation work
m_guard_calculation.unlock();

Main Thread:

void update() //called every frame
{
    if (m_guard_calculation.try_lock()) //only visualize if not locked, otherwise just skip
    {
        // do hard visualization work
        m_guard_calculation.unlock();
    }
}

in that scenario my calculator thread will stop working at some point. I assume that I have to wake up my calculator thread somehow. How would I do that?

0

There are 0 answers