Antonio Santoro
Antonio Santoro

Reputation: 917

Running a packaged_task after extracting it from a queue in mutual exclusion using a scoped_lock

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

Answers (0)

Related Questions