Commit 476818df authored by eric's avatar eric

bugfix to prevent accessing to reclaimed task

parent 8b74f72a
...@@ -348,12 +348,17 @@ void TimerThread::run() { ...@@ -348,12 +348,17 @@ void TimerThread::run() {
// Pull tasks from buckets. // Pull tasks from buckets.
for (size_t i = 0; i < _options.num_buckets; ++i) { for (size_t i = 0; i < _options.num_buckets; ++i) {
Bucket& bucket = _buckets[i]; Bucket& bucket = _buckets[i];
for (Task* p = bucket.consume_tasks(); p != NULL; Task* next_task = nullptr;
p = p->next, ++nscheduled) { for (Task* p = bucket.consume_tasks(); p != nullptr; ++nscheduled) {
// p->next should be kept first
// in case of the deletion of Task p which is unscheduled
next_task = p->next;
if (!p->try_delete()) { // remove the task if it's unscheduled if (!p->try_delete()) { // remove the task if it's unscheduled
tasks.push_back(p); tasks.push_back(p);
std::push_heap(tasks.begin(), tasks.end(), task_greater); std::push_heap(tasks.begin(), tasks.end(), task_greater);
} }
p = next_task;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment