sleep the thread instead of yield in cooperative scheduling

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
User avatar
taufiqwidi
Posts: 7
Joined: Fri Jul 05, 2019 11:19 pm
Has thanked: 1 time

sleep the thread instead of yield in cooperative scheduling

Post by taufiqwidi »

hi,

sorry for this newbie question but, can we sleep the thread for specific amount of time instead of yield in the cooperative scheduling?. cause i cant make it work to sleep the thread when in cooperative scheduling.

Thank you,
Taufiq
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: sleep the thread instead of yield in cooperative scheduling

Post by Giovanni »

Yield is not for making the thread sleep, you need chThdSleepMilliseconds().

Giovanni
mikeprotts
Posts: 166
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 19 times
Been thanked: 31 times

Re: sleep the thread instead of yield in cooperative scheduling

Post by mikeprotts »

chThdYield is good when you have equal priority threads and you want to avoid them blocking each other, but run without delay if possible. If threads are not equal priority you'll always get the higher priority jumping back in.

chThdSleepMilliseconds and chThdSleepMicroseconds are good for threads that need to perform processing in a fairly periodic interval, or where an asynchronous task is expected to complete in a predictable time. The interval is not precise, especially when small.

chThdSuspend in a thread, then chThreadResume (from another thread) or chThdResumeI (from an interrupt) is good when you want to start processing based on an event. This allows the processor to idle, or let a lower priority thread run.

Mike
Post Reply