0

Unfortunately, I don't have access to the newer versions boost - only 1.33. Basically, I would like to do the following:

void threadFunc() {
    while (true) {
        {
            getALock();
            doWork();
        }
        // sleep for x unless signaled to wake up or boolean changed to
        // stop doing work.
        if (toldToExit()) return;
    }
}

The main thread would start up the thread, let it do work for an infinite amount of time and then eventually, tell the to stop doing work and die. The only problem is that I want the thread to wake-up immediately after the main thread tells it to stop. Like I said, I only have what is available in boost 1.33. How can I achieve the above? If possible, I'd rather avoid using pthreads.

laluser
  • 149
  • 2
  • 9
  • take a look at condition variables and timed_wait function which gets interrupted after amount of time slept or being woken up by conditional variable in this case lock - at least I think so – Aleksander Fular Oct 22 '13 at 07:34
  • http://stackoverflow.com/questions/12437395/a-simple-example-of-boost-multithreading/12437526#12437526 – Alex F Oct 22 '13 at 08:15
  • Alex, that example is using thread interrupts which are not available in 1.33. – laluser Oct 22 '13 at 21:38

0 Answers0