Hello, welcome back and listen, we going to see how to work with mutex we saw how to use semaphores.
I've made a copy of our last project, which is our always for and I've called this one which mutex
it is over here.
I'm going to expand it and open the main door.
See far from here.
And we simply going to convert this project to a mutex so a mutex takes a simple structure, a simple
structure of attributes we need.
No, actually let's go and find a mutex.
This is all documentation.
We have to track everything down together.
It's better that way.
So this is mutex management.
OK, so the mutex has an attribute.
OK, and then there is the new text, new function, let's see this.
The function simply takes the attributes.
OK, so over here we have an attribute for our semaphore, which we call currently, which we are calling
you at for our troops.
So we're going to replace this with a mutex attribute.
So this attribute is of type always mutex Atiyyah.
So I simply replace this with a mutex attribute, and I'm giving this a new name, you automatics,
and then the name of the troops or the attributes is you.
You are mutex attributes.
So then I'm going to come down here to create the mutex where we created a SEMAFO.
Over here, we simply replace the function here.
With mutex.
So before we do that, we have to create an I.D. to hold our mutex so we're going to create a US mutex
ID data type.
Over here, we have a semaphore type, we're going to delete this and have a mutex type going to call
this, you add MOUT.
OK, right.
So once this is done, we'll go ahead to create a new mutex.
So I'll scroll down here where we created a SEMAFO.
I'm going to come in this out and create a new mutex.
Then, like we said, simply takes the attributes as argument.
This what we saw in the documentation.
OK, so once this is done, we can simply go and replace our SEMAFO Akwa of release with mutex.
So over here, rather than see SEMAFO acquire, we simply save mutex acquire.
Always mutex Akwa and rather than see always SEMAFO release, you say always mutex release.
And then we do it for the other one, this one here, red, a little controller ask rather than, say,
WMI for Akwa you say always mutex Akwa and we release by calling the voice always mutex release function
like this.
OK, let's do wait and see what we've got.
Click over here to build.
It's built in.
Oh, OK, so I forgot to change the ID of the function.
He has to be the mutex ID you are to ID a copy this.
Replace it here and replace it here, let's build.
Click here to build.
Oh, sorry about that, I forgot to replace in the release, so we acquire and then we release, we
acquire and then we release.
We had to build.
It's pure successfully, we're going to run this right click over here, I'll see dbag us SDM 30 to.
So like this, forty three.
It's opening, I say, OK.
Well, click here to switch.
Then.
I screw this over here, I'll minimize this.
I'm going to clear this and then I'll pull this over here and then I'll click to run.
Nothing is running.
Let's pause and see.
How were you at, says, waiting for the UDS?
OK.
The port is closed.
I'll click to run and then open up ports for the.
As you can see, we have the same results as I was.
OK, so this how to use the mutex.
So there is and I'll see you later.
Have a nice day.