This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CMSIS-RTOS RTX: something like "osDelay(0)" possible?

Hi,

I like to do a manual thread switch like osDelay will switch to a new thread, but without a timeout value, simply something like osDelay(0).

As far as i can see, there is an function osThreadYield, but this function switches to the next thread with an equal priority as the switching thread. osDelay will block the current thread and put in on the delay list, but switches to the next ready thread in the order of the thread priorities, exactly what i want, unfortunately, an delay value of 0 is not allowed there. Is there another way to do thi styp of manual thread switching?

Martin

  • Remember that osDelay(0) would not really have switched to a lower-priority thread, since zero would mean that this thread is instantly ready again and so should win over a lower-priority thread.

    The only way to switch to a lower priority thread is to make the current thread wait a fixed time, or until some specific event happens. Only then would the OS see a reason to look for a lower-priority thread to run instead.

    So maybe it's time for you to rethink your thread priorities. Maybe your lower-priority thread really shouldn't be lower-priority but should be higher-priority but waiting for an event. Then this current thread would be able to just post a mail or set an event to get the other thread to start.

    Yield doesn't have this issue, because a switch to another thread with the same priority doesn't put the OS scheduler into any issues - with same-priority threads it doesn't matter that the yielding thread is already ready to be run again. And that's why yield and delay(0) can't be behaving the same.