Hello, welcome back.
And this lesson we going to experiment with task priorities, so far we've been creating tasks with
the same priority level.
This time we agreed to experiment, changing the priorities and see what happens.
I'm going to make a copy of our Task Creation Project Project's number one over here.
I'll call this number for.
TASC Priority's.
Or top priority, singular is better.
OK, I'm going to open this.
So in this project, we had three tasks blue, red and green, and each of them had a profiler and they
had the same priority just to refresh your memory.
Let's see what happens when we run this.
Remember, in each task function, we have the profiler.
We increment in these variables.
So we're going to observe them in the live expressions window to see the behavior, whether they are
similar or click over here to build.
Go to Dybbuk.
A select number four here.
And then OK.
And then I'll switch.
OK, I'll go to live expressions over here and then.
A, you see, they have almost the same values.
OK, we can post this, the values are almost the same, almost the same.
Right is because they have the same priority, meaning each of them is executing the same amount of
time, 10 milliseconds or one milliseconds based on our take rate or based on our time quanta systems,
which we shall take a look at when we start looking at the last sentence.
For example, if the CUENTA is set at 10 times, this means each task would execute for 10 times 10
milliseconds.
That's what that means after 10 a.m. is the scheduled.
Schedules, the next task, the first task stops executing and the next one executed for 10 months as
well.
And then the next one, so they'll end up with the same amount of execution as we can see over here
with our count of variables known as the task profiler.
OK, so stop over here.
What I'm going to do now is.
I'm going to change the priority of task number of task green over here.
I'm going to change the priority to to remember the smaller the number, the higher the priority.
So changing this to priority to effectively makes this the lowest priority amongst the three.
So click over here to run.
And then click here, debug.
And then switch.
And then click here to run.
That's right, strange.
We have just.
Green running.
Oh, Green has priority of two.
So let's see.
OK, so, yeah, the reason Green is running is twofold.
Oh, explain.
So in free, the larger the number, the higher the priority.
Unlike other time operating systems that I'm used to, I have courses on four different time operating
systems.
So you should bear with me when I make this confusion.
So with free ARTUS, the larger the number, the higher the priority.
So.
Number two over here is essentially the largest priority number, the other tasks have task priority
level one one, and this has level two.
So as the highest priority number.
Right.
So what is happening here is that there are certain rules to the shetler, one of the rules is that
a lower priority task cannot interrupt a higher priority task.
What that means is as soon as your tasks stop having the same priority level they no longer operating
in, in the timesharing mode that I explain, the time sharing mode is the mode where each of them is
assigned a specific amount of time to execute.
Once they are done executing, the next task is executed.
This happens when all of them have the same priority.
This is known as Round-Robin scheduling, but as soon as one has a priority greater than the rest,
just I want to execute.
Why?
Because a lower priority task cannot overtake a higher priority task.
And we should explain this further in theory when we look at the task states.
Right.
So the reason this is executing is that this is the highest priority task.
These tasks have lower priority.
So they cannot they cannot interrupt this task and execute.
That is why this is the only one executed you would see over here or the others are not blue and red.
They are just stuck in this one.
Blue and red have a lower priority compared to green.
OK, so we're going to increase the priority level of red and see what happens.
We said right to two, I'm going to click over here, so now we have.
Green and red with the same priority, blue has a lower priority, which is one click here to build.
Click here to download onto the board.
And then switch over here.
And then I'll click here to run, and I can see now we have red and green running and blue, the lower
priority cannot interrupt the higher priority, but if they have the same priority, they share that
time amongst themselves.
So now they are just passing the ball to each other.
All the scheduling is the one doing this.
The schedule is the one assigning the time to read and then to green to read and then to green because
blue has a lower priority.
OK, so let's see something.
What if I increase their priority level of blue to number three such that blue is three, red is too
green is too.
Let's see what happens.
I'll click here to build.
And then a click here to get onto the board.
And then click here to switch.
And then click here to play, as you can see, Lou, is the only task running because it's got the highest
priority and these ones don't have a priority equal to blue, so they cannot get any of the time.
OK, so these are some basic stuff.
Next, what are we going to do in?
The next lesson is to see how to change the task priority in real time.
Over here, the priority is assigned during the the creation of the task.
What if, let's say read, execute and we want to drop the priority of red after we've computed something
else.
We'll see how to do that in real time.
And by real time, I mean in runtime.
That's why I should say, rather than real time.
OK, so I'll see you in the next lesson for that.