0

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.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Antonio Santoro
  • 827
  • 1
  • 11
  • 29

0 Answers0