Pages: [1]   Go Down
Author Topic: Suggestion: don't call yield() in delay()  (Read 1252 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
Karma: 67
Posts: 1655
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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().


Pages: [1]   Go Up
Jump to: