-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix unprotected access to task_queue_.begin()->first in Scheduler #1084
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,10 @@ void Scheduler::serviceQueue() { | |
new_task_scheduled_.wait(lock); | ||
} | ||
|
||
current_timeout_ = task_queue_.begin()->first; | ||
while (!stop_requested_ && !task_queue_.empty() && | ||
new_task_scheduled_.wait_until(lock, task_queue_.begin()->first) != std::cv_status::timeout) { | ||
new_task_scheduled_.wait_until(lock, current_timeout_) != std::cv_status::timeout) { | ||
boost::thread::yield(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why do we need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to give up our cpu time slice, since we are going to wait again |
||
} | ||
if (stop_requested_) { | ||
break; | ||
|
@@ -43,6 +45,10 @@ void Scheduler::serviceQueue() { | |
Function f = task_queue_.begin()->second; | ||
task_queue_.erase(task_queue_.begin()); | ||
|
||
if (!task_queue_.empty()) { | ||
current_timeout_ = task_queue_.begin()->first; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we wouldn't need to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to think we should still set it to the current worker but also signal the change to all other workers so they can update their timeout. But perhaps I'm overthinking it? |
||
} | ||
|
||
lock.unlock(); | ||
f(); | ||
lock.lock(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're not updating
current_timeout_
within the loop, could it be an issue? what if someone adds an earlier task in the scheduler?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that might be an issue. I don't know how we can correctly update the timeout for all threads when a new task is added. Maybe re-setting in the loop and do a
notify_all
on insert?