3,970 questions
How you do this depends entirely on what you are doing. One really simple case is the following.
#include <mutex>
static std::mutex s_queue_mutex{};
void thread_proc()
{
//do other thread stuff
{
std::lock_guard<std::mutex> guard_queue(s_queue_mutex);
//modify queue
//guard_queue will destruct and unlock the mutex
}
//do other thread stuff
}
This creates a global std::mutex
that will be used by all threads to protect the queue, and you just use std::lock_guard
when you want to protect the queue.