8 years, 10 months ago.

Threads Execution in RTOS mbed

I am using signals to start a thread,i.e,when a signal is set, the thread corresponding to that signal is executed. Now imagine a situation where a signal for higher priority thread is set while a lower priority thread is being executed. What happens now? Which of the following cases occurs? 1)Higher priority thread starts getting executed and after that the remaining part of lower priority thread gets executed. 2)Higher priority thread gets executed and lower priority thread is left without completion. 3)Lower priority thread keeps executing and higher priority thread gets executed after the completion of execution of the lower priority thread. Similarly.what happens when a signal for lower priority thread is set while a higher priority thread is being executed?

2 Answers

8 years, 10 months ago.

It would get a mess if once a higher priority thread is started, the lower one gets ignored. That would remove the point of threads.

So with a higher priority thread getting started, that one will be executed immediatly, once it goes into a wait state the lower priority one gets executed. The other way around, the lower priority one will be executed once the high priority one goes into a wait state.

What happens when you have two maximum priority threads triggered close to the same time (i.e one is currently still executing while the other triggered)?

posted by Krzysztof Sitko 15 Jun 2015

They will alternatingly run. But don't ask me how exactly, you can also just try it out.

posted by Erik - 16 Jun 2015
8 years, 10 months ago.

you can read about it here http://www.keil.com/rl-arm/kernel.asp

All threads should be of a type that runs until it blocks (mutex, event, ...) In pre-emptive mode So most threads are waiting to be told to run. (by interrupts, events, unblocked mutex, ...) lower priority get told to run, it runs, higher priority thread preempts lower priority thread, but when higher priority thread blocks, lower priority thread resumes execution where it was preempted and runs until it blocks or is preempted again. If no threads need to run, then the idle thread runs.

you should read up on "fixed priority preemptive scheduling".

you can look at Round Robin, or Co-operative, but those are much the same as using a simple foregroung/background super loop.