Reputation: 917
I need to execute an extracted task from a queue after locking two mutex using a scoped_lock, the problem is to swap a task from a queue to another one and then execute it. So far this is my starting point
std::packaged_task<void(Job)> task;
{
std::scoped_lock scopedLock(w_mutex, r_mutex);
const std::packaged_task<void(Job)>& top_task = waitingJobsQueue.top();
waitingJobsQueue.pop();
runningJobsQueue.push(task);
}
task();
but I'm not able to save the task into a variable to execute it later.
Upvotes: 0
Views: 52