I have one producer thread and several consumers, every consumer has: own queue with data and unique id. I use std::map to identify each queue for thread.
typedef std::map<int, std::queue<Task>> TaskMap;
TaskMap inputQueue;
TaskMap outputQueue;
Each consumer thread work with data in his queue, if queue is empty, thread must wait for data. If i want to do it with only one thread, i can use std::condition_variable with std::unique_lock, but i have several consumers so i need several std::condition_variable, but i cannot save them in containers (copy/assignment are deleted). So i use code like this
while(q.empty()) {
std::cout << "waiting...\n";
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Where q is reference to queue. But how can i synchronize it with better way? Thanks in advance. P.S. Queue will always has data, last data must say 'exit'.
emplaceandat. - zch