So right now, we have talked about semaphores, but what happens when priority actually changes now,
not all that priority.
For example.
Let's say that you have some death and you have other emergency desk, so it could be a safety test,
your controller is doing its regular thing, then maybe some kind of alarm happens and there should
be an execution routine done by the microcontroller in order to prevent some catastrophe from even happening.
This is why in this case, you need to assign a different priority to your task to safety test.
It could be a task in order to fight some fire.
It could be a task in order to stop some of the machines when the head of the maintenance to say, is
stuck in between gears of the machine.
Well, there is a lot of safety concerns that we need to care about.
Now, the higher the number, the higher the priority we have.
So zero is a low priority, one is a higher priority, and two is the highest priority.
So let's say serial one has a higher priority than serial two.
Let's see what's going to happen right now.
I was still going to get one, two, one, two, one, two.
Or when we are trying to compete for resources, they are your priority is going to take place.
Let us see.
So far, we were fluctuating between one and two, one and two, right, even though if you were having
backlashing, it doesn't matter, then both have the same priority.
We will still be fluctuating between one and two.
Now, I have uploaded a sketch where to where serial one has a higher priority.
Let's see the output and let us take a closer look.
We see that here we are printing one, two, one, two, one.
And then we have a clash.
As you can see, it's printing one one.
Why?
Because we are having a clash.
We are competing for semaphore.
And the higher priority is the one is going to win.
This is why we are getting one.
Let us continue and see.
One, two, one, again, one, one, two, one, two, one, two, one, two.
No problem.
Then what one again.
This one competing for resources.
The higher priority is the one that is going to win.
Now, let me try and reverse the priority here.
Let's say this one has a zero and this one has a true priority.
Now, this one has the higher priority through your do is the highest priority.
Let us upload this and see what's going to happen.
Let us check.
I'm going to clear the output.
Again, we have two, two, one, two, one, two, one, two, one, two, then we have to watch you
here.
So we are competing for resources or semaphore to has our priorities.
So, too, is the winner.
Two is the winner in this case again.
Due to.
Again.
And again.
So this is why we have priorities, because if two deaths competing for the same resource and one of
them, let's say again, for safety or for emergency stop or whatever, this one is the one that is
supposed to win now handling the other services and the other tasks when the higher priority task executes
in order, let's say, to stop the whole line is a different issue.
That is a totally different story here.
What we are talking about is who wins when we have a competition between higher and lower priority.