-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
A purely coroutine based multi-tasking system needs all tasks to be good citizen of the cooperative multi-tasking system, yielding the CPU to other tasks in a periodic manner, enabling long running compute intensive tasks to run while not stopping other tasks from operating.
A yield awaitable object is a clean way of achieving this goal. It can be awaited periodically in long running loops:
task<> do_some_long_computation(int iterationCount, auto &&operation, priority myPriority)
{
for (int i = 0; i < iterationCount; ++i) {
// Perform one iteration's work
operation(i);
// Yield the CPU, signaling the queueing system our priority (optional argument)
co_await cpu::yield(myPriority);
}
}An example of such use is for the SSD1306 code. Filling the OLED screen buffer to print text can take tens of thousands of cycles.
The routine performing this operation should be capable of yielding so that time-critical operations can take place.
hattesen
Metadata
Metadata
Assignees
Labels
No labels