Hello, welcome back.
In this lesson, we going to see how to change the priority of a task during runtime using the Simms's
artists to appraise, I've going ahead to make a copy of our last project, and I've given it the name
thread priority over here.
And we're going to run this simple experiment so we know how our current project works to refresh your
memory.
I'm simply going to run this.
I'm going to build this.
This is our new project.
Right, and I'm going to run it.
So I'll see debuggers ASTM 32, iSelect 36, and it's going to go to the DeBacker.
It's open in.
Now click here to switch.
OK.
So when I click this, I'll run and all of them are running the incrementing the same because they all
have the same priority.
OK, so what are we going to do?
Is we going to let the orange task or thread change the priority of the.
Of, let's say, the green thread to do this, we need to add something else to our threads.
When we create our thread, our thread retains an idea.
We need to store the idea of the thread somewhere so that we can use the idea of the thread to access
or control the particular thread we are interested in.
So I'm going to come up here and declare for variables of type.
Always thread on the school, always thread.
It is called actually Enniscorthy.
That's the type, and we're going to have read it for our red thread.
We're going to have green eyed creature of blue eyed green to have orange eyed.
OK, so what are we going to do is whenever we create a threat, the ID is retained.
We didn't make use of this ID in our first example, but now we're going to make use of it.
I'm going to copy the Green ID and I'll come over here when we create the green thread is going to return.
The ID will start here and I'm going to do the same for all of them.
OK, this is for Red Threat is going to return the ID stories and read it over here.
And I'm going to come down here.
This one is for Orange Threat is going to return the ID.
I'm going to store it over here.
Range like this, and finally, Blue is going to return the ID and I'm going to store it in blue, ID
like this.
OK, so now that each threat has its ID stored, we going to use the thread ID to change the.
Priority of the green threat, so I'm going to come to the orange threat when the orange threat executes,
when it's executed was is going to set, let's say it's going to increase the priority of the green
threat.
So we come over here and the function we use, which we can find in our documentation.
Remember the documentation I showed you how to open it for a reason or the functions can be found here.
OK.
Right, so we can come over here and we say always thread set priority, so this takes two arguments.
The first argument is the idea of the thread, whose priority you want to set.
We want to set the priority of green.
Thread, so the next argument is the new priority you want to assign to it over here, we want to give
it a priority above normal one.
So I'll see.
Always priority.
Above normal one like this, and we saw the table where we had a list of priorities, OK, if you want
to know more about the priorities.
You can find them here.
The states, the priorities, so there's always priority, non priority I do this is this priority is
in descending order of magnitude.
The the the higher the priority, the lower it is in the stable.
OK, so that's priority.
No more.
Plus one you say always priority number one.
No more plus two is always priority normal two etc..
OK, and then there is always priority.
Hi.
I wonder how come they decided to name it this way.
In any case, we're going to give this always priority one because our threads here have always priority
normal.
So we know after the execution of this line, the highest priority thread becomes the green thread.
Let's see if this works.
I'm going to click here to build.
I think there is an anomaly.
Huh?
OK, over here, I misspelled priority.
Click here to build again.
It's built in.
To build successfully, going to click here to download onto the board.
It's open in.
Click to switch.
And.
It's ready, so I'm going to click here to run.
Let's see what happens.
OK, so now we have just the green thread running across, indeed, we were able to change its priority
in runtime using the OS thread priority search function.
So that's all there is if you wish to change the priority in runtime using CMS is outsourced to API.
It's as simple as this.
OK.