Welcome back.
In this lesson, we going to see how to create threats manually.
So let's say you have generated your code with Cuba mix and when you arrive here, you realize, oh,
I would need another threat.
Well, you can just follow up how the other threats were created.
We start off by creating the arm, by creating a threat I.D. So I'm just gonna copy the threat idea
here.
I'm going to create threat three.
So I renamed this threat Hando to Threat three.
Hando Once the I.D. created, we come over here and then we use the U.S. threat death to create a threat.
I'm going to create an exact replica of threat.
Wanted to copy this over here and then paste it.
So what is going to happiness?
We have always threat.
The first argument is the threat.
Name.
The first argument is the threat.
Names who are called as threat to a threat.
Three.
The second argument is the threat function, which we should define later.
Our code is Threat three fund.
The argument of today is the priority and then the argument which we have zero debt.
If we want to know more about this argument, we can actually view this and the threat that the threat
would see fall, which you can find over here.
I'm gonna keep this zero argument to what it is.
This is the stock size.
Um, I think I've forgotten what a zero stands for.
Um, we can find that out.
Let's see.
So to find this out, I'm gonna come to the, um.
To the middle where third party free ARTUS source and then I'll go to tasks to see.
And then what we are looking for is the US threat def.
This is something DeNardo control f always threat def.
Let's see if we have it here.
OK.
It doesn't exist here and always threat def.
It doesn't exist here.
OK.
The reason it doesn't exist here is this should be found in the Ms.
Ms is always dot h.
This is not a this is.
No this is not a call if we are to us function.
This is the function that was wrapped around free Archos by Simms's.
So let's find a Simms's fault and find the meaning of that.
We simply need to come up here in our main dot C file and then.
Right, click on CMC Spoilsports H Coutu declaration.
And this will also give us the chance to see the different aspects, such as the number of priorities
and other things we have.
OK, so what does the CMC Stone Age for the API.
We are using are from this file over here.
So you can spend some time looking at this.
OK.
So these are the priority levels.
We have the ideal priority.
This is the lowest minus three.
We have always priority low.
This is minus two.
Below normal.
It's minus one.
Normal is you priority above.
Normal is plus one.
We have high priority.
We have real time priority.
We have.
Priority.
These are the priority types.
And they are always status types, which we've not looked at.
And then, um, all we are looking for is a while.
Always the red dev function.
This is it.
Always the red death.
The first name is a pointer to the thread name.
The second name is the start address of the thread function, which is basically the thread function.
This is the priority.
What we the zero that was confusing us is this one here.
Number of instances.
So you can have a single thread and have multiple instances of the same threat.
So we pass in zero day because we know create infinite instances.
So this argument is number of instances.
And the last one, of course, is the stock size.
And if you want to learn more about the API is available, you can certainly spend more time in this,
followed by here.
So we know what that means.
Now, this is a number of instances.
So zero instances.
This the stack size.
So once we've used the OS thread def.
To to set these parameters.
We come here and then we use the always threat create and then to create a threat who is threat create
and then is threat three over here.
And this is going to return to threat under which we shall store in the threat I.D. that we created.
So it's gonna be stored here.
Right.
So change the comment here to threat three.
Remember, we have threat three over here.
So the steps.
Step one, we declared a handle to store the threat handle.
When it returns.
And then we use the always threat def to define DRM, the parameters of the threat.
And then we create the threat using the OS threat.
Great.
Once that is done, we have to go ahead and define the threat function.
So I'm gonna come down here and the threat function has to take this format.
It's void.
It takes constant point-I argument.
So I'll copy this pasted over here.
I copy the lymphoid
conclusory to copy control to paste open and close.
And then I'm gonna change this to threat three func.
Remember we already told our OS threat def that the threat function is called Threat three fund.
As you can see over here.
So that is why I'm using the same name.
OK.
And its priority is just like the others.
And in here you can just put your infinite loop.
Remember threats.
Main threats have to have infinite loops.
The other forms of threats that are time are threats, interrupt threats.
Those don't don't have infinite loops.
Those have to return.
And just to RAAM to make sure it is working.
Let's add our profiler to it.
Let's profile this threat and see.
So in our profilers, I'm going to come over here at a new one thread, three profiler like this, and
then I'm simply going to go and incremented.
So I'm going to come down here.
This is our threat three function.
I'm simply going to this profiler.
So now let's go and see if this increment unless she did I forget to train this to Profiler three.
Okay.
When I posted this here, he has to be three.
Okay.
So let's go and see when I click to build.
Click over here to build.
It's built in.
We've got to rush.
Let's see.
Let's see, let's see.
Right.
Three function is good work with zero come from.
Okay, should be up there somewhere.
Who is threat or those who see it over here?
Huh?
Okay, so I suspect I know the reason is because our thread function, the prototype of the function
has to be placed on the top of the fall.
Remember, the function is declared below this line.
So it's not accessible because of that.
We've got to put a prototype of thread three.
You see, we have the prototype of all our threat functions at the top here.
So copy this pasted over here.
Change this to number three like this and then click over here to build.
It's Putin.
We still have two errors.
Let's see what does it say?
Three.
Oh.
Okay, so the other issue is I have a typo in this word here.
It should be one H.
And yeah, I'll fix that here.
Three, three fingers, one each.
Okay, let's build and see.
Click over here to build.
We have one error.
Let's see.
This time is somewhere else has to be done here.
All right.
Three phone calls for gonna open this up a bit on defined reference to threat, three funk.
OK, we still have our two H over here.
Share a border.
Click over here to build.
It appealed successfully, gonna get onto the board and go to the debugged by clicking here.
It's opening.
So I'm going to profile thread number three.
I'm going to remove all of these from the old project or old experiment or copy thread three profiler,
go at it over here.
Remember, thread three has the same priority as the other threats or tasks.
Click over here to run and you can see it is running.
So our new task or threat is executing as well.
Right.
So that's all there is for this lesson.
We've seen how to create a threat manually.
I mean, the next lesson we're going to see how to how to send notification between threats or soon
the next lesson.