Go Down

Topic: Suggestion: don't call yield() in delay() (Read 2128 times) previous topic - next topic


Changing delay to call yield will introduce subtle bugs.  Even coop schedulers will have problems.

For example, a library that calls delay while accessing a device on the SPI bus may inadvertently yield to another thread that also accesses the SPI bus.

Introduce another weak function like yield and call it something like "sleep".

The weak version of sleep() would call the unmodified version of delay().

Schedulers and preemptive RTOSs could implement appropriate behavior for yield() and sleep().  Library writers will have more control of thread execution.

A coop scheduler would call yield() in its version of sleep().

A preemptive RTOS like ChibiOS would call chThdSleep() or chThdYield() as replacements for sleep() and yield().

Go Up