Hello.
Welcome back.
So in this lesson, we are going to see how to how to access a single resource from multiple threads
or tasks by the help of a new text when using mutex.
There are two functions or two API.
We need we need the, um, the new tax give and the new tax take or the semaphores take and the semaphores
give me Texas, that type of semaphore.
So, um, I'm gonna come over here.
This is my third one.
You can think of the mutex as a key, a single key to the rest room or the toilet or the um the restroom.
I know you get what I mean.
So if you want to go to the restroom, you pick up the key and then you open the door.
When you finish using it returned a key such that the next person can pick up the key.
Open the door.
And when different issues in it, they return.
So we are going to use them.
Ex semiformal take to take the key, so say ex semaphore, take does the name of the API.
And this here takes the name off.
The key name of the key is our new tax I.D..
Over here.
The new text we created in Cuba makes its code.
You add new tax on those who control see to copy.
And then I'm going to put this here and then we're going to add some delay here, such as it is a form
of a timeout.
So I'll say put Max DeLay and put Max DeLay means this is, um, infinite timeout.
Meaning don't move on, too, until you get a key.
You can put an amount of time here, such as fry them as such that if the key doesn't arrive in five,
Emmis, break the door and enter.
But if you put port max delay means if the key doesn't arrive.
You cannot open the door.
The door is still locked.
But if we put something before, put an actual number here, which is not put to Max DeLay 10 M as hundred
M as it means, if the key doesn't arrive within this time, you can go ahead and try to enter.
Right.
And you can think of the bathroom being that you got that you are the driver, the restroom being the
are the driver.
So wait, wait for infinite time until the key arrives before you can enter the restroom, which is
the you are driver once you are done.
You can return to key.
We this uh this API should be you at take.
I forgot to put a word take here.
Once you are done you can return the key by saying x semaphore.
You can give back the key x semaphore.
Give like this and the name of the key is you are to new text Hondo.
Right.
And when given the key there is no time involved.
So this is it.
So the same thing is going to be done for our our threat to thread two would also need to take the same
key.
The key name is the same.
And we say, wait two.
The key arrives.
Wait.
An infinite amount of time once you are done.
You can also return the key.
The same key.
Like this.
OK.
I hope you understand the analogy so we can build now and see what we have a quicker way here to build.
It's built successfully.
Click here to get it onto the board.
It's download in.
It's downloading.
OK.
It's, quote, onto the board.
Click here to stop.
OK, so now we can go to war to return to see.
Select.
I was to report from here.
This one over here, then change the board bodyweight.
It's the correct but rate.
OK, now we can see the returns from third one greeting from threat to almost equal amount of threat
one and three, two.
In fact, they have equal amount of access to the U.
S.
So this is the beauty of new tax.
And you apply the same method when dealing with an LCD screen.
If we replace the you out with an LCD screen, let's say we wanted to send the same message onto the
screen.
We would need to just use the dramatics to do that.
So, yeah, this is how we solve the multiple access to a single resource using a new text.
If you have any questions, leave it in the questions and answers area.
Right.
So this saw there is the next lesson.