Details
-
Improvement
-
Resolution: Won't Fix
-
Major
-
None
-
master
Description
Abstractly shown are two function involved in the tasks run management.
// The actual task run function - executes on a NONIO thread
|
bool ActiveStreamCheckpointProcessorTask::run() {
|
snooze(INT_MAX); // sets the task to appear asleep
|
notified = false; // atomic_flag set to false
|
... task work - drain the inputQueue (up to some threshold of items ) ...
|
|
// if notified == true, set it to false and return true
|
if (notified.cmpxchg(true, false) OR inputQueue.empty()) {
|
A: request this task to be rescheduled at next available opportunity
|
}
|
}
|
|
// The wake function - executes on another thread, this function requests that the task starts running
|
void ActiveStreamCheckpointProcessorTask::schedule() {
|
// if notified == false, set it to true and return true
|
if (notified.cmpxchg(false, true)) {
|
B: request this task to be rescheduled at next available opportunity
|
}
|
}
|
In the run() function, the final cmpxchg isn't needed, if we did find that notified was true we can be sure the other thread has done B, we only need to evaluate the inputQueue size to determine if the task should self-schedule.