thread_yeild

Hello,

if the thread_yeild function is called from within an ISR, then when does the program exit the ISR. Does the scheduler make sure that we exit the ISR before running the new thread or do we continue to be in the ISR?

Thanks a lot for the help!

Regards,

Abhinav

Dear Abhinav,

`thread_yield()` is used a lot in the periph drivers for i.e. stm32f* CPUs in the following manner.

...
if (sched_context_switch_request) {
    thread_yield()
}

This way the scheduler performs a thread change (if requested) then the ISR is finished and returns from interrupt context into the newly scheduled thread.

Hope this helps!

Best, Thomas

Thanks Thomas - This is what I was hoping to hear! Regards, Abhinav

Hi Abhinav,

the situation for the cortex-mx platforms is sligthly more complicated:

The `thread_yield()` call tells the controller to trigger the PendSV interrupt. This ISR has the property, that it is executed after all (higher prioritized) active interrupts are serviced first. In the PendSV handler the actual context switching takes place and the controller is then put back into `normal` thread mode (see `thread_arch.c` in the `cortex-mX_common` folders`. But I guess the effect stays the same: calling `thread_yield()` will trigger a context switch (if applicable) and the resulting thread is always run in non-interrupt mode.

Cheers, Hauke