mercredi 4 novembre 2015

Wait for either condition A or condition B in a std::thread

I have what seems a fairly simple need, but I'm new to using std::thread and am not sure I understand it right.

My thread's job is to run a loop: wait until an object needs processing, then process it, then wait, ...

I was about to implement this using a condition_variable before I realised that while the thread is sat idly waiting for a new object, it won't notice a stopThread flag has been set.

I effectively want a way to do wait_for_either(new_data,exit_thread) but am unsure how to elegantly implement this. Older code of similar queue function uses Windows API WaitForMultipleObjects but I want to use this as an opportunity to learn the C++11 way.

Aucun commentaire:

Enregistrer un commentaire