Hello, welcome back.
In this lesson, we go in to see how to work with semaphores using our Simms's outer space and going
to make a copy of the last projects over here.
My computer and I responded just a moment.
OK, I'm going to right click, copy and paste over here, I call this 42.
I call this.
Over semaphores.
Like this.
OK, so we're going to expand this and open our mind to see fall over here.
And this a copy of our last project in the last project we created, The Time is OK, and also in this
project we have.
We have four tasks and they all have different priorities.
We can send them back to normal priority.
We can either let them or have the same priority or keep this.
But I'm going to set all of them to priority normal because we wanted to run a different experiment
when we changed our priorities.
So we have four tasks of the same priority and we have two timers.
We don't need a timers.
We can keep it without cleaning it.
OK, so we are here to find out how to deal with semaphores.
So semaphores, we have to go to our documentation to see what apps we have available for us.
OK, I'll come over here.
And then there is semaphores punishment here, click this dropdown.
And over here.
Let's see the SEMAFO Hassan attributes just like the task, so let's find out what his attributes looks
like.
So this attributes.
The name of the SEMAFO attributes bit memory control block the size provided.
OK, so we just going to give our SEMAFO and name.
We're not going to assign the other attributes.
OK, so now let's see this function or SEMAFO new see.
So 074 new.
This function creates an initializes a SEMAFO object, so this is what we would use to create our semaphore,
and this function, as we can see, takes three arguments.
The first argument is the maximum count of the SEMAFO.
And then the second argument is the initial count, and the third argument is the attributes.
The attribute structure, so from here, we know we are creating a account in semaphore, right, so
there is maximum initial count and then the SEMAFO attribute, such as the name and the other stuff
kept in the attribute structure.
OK, and then of course, after that we would have our SEMAFO or SEMAFO receive and some of our acquire
and then the other functions gets count, delete, SEMAFO gets the name of SEMAFO, etc. So we know
what to do.
So we have to declare an attribute, just like our tasks here have attributes.
The SEMAFO has its own attributes and the attribute structure has its own members.
But what are we going to do here is just create we're going to create a simple attribute.
This will have just a name.
So come up here.
I'll have this attribute SEMAFO attributes I could have created inside of me and function.
It is fine, but I'm creating it here.
OK, and we given this the name you are SEMAFO and then we're going to declare a Hando or a SEMAFO idee.
So Hindoos that we had in the native free Arktos APIs are called IDRs in the Simms's Arktos space.
So we create an idea for some of what we're going to call this UAT.
Same idea.
Once that is done, we going to create our SEMAFO, we're going to create a SEMAFO of a maximum count
of one and we're going to set initial count to one as well so that our first task will be to know the
SEMAFO would have access to it.
So I'm going to come down here before we start the scheduler.
We create our SEMAFO.
And well, criticism for the handle of the SEMAFO is going to be retained and stored in our new outswim
ID or the idea of the SEMAFO to use the language of Simms's Arktos.
The ID is going to be retained and we're going to start it over here.
OK, so then we're going to use this SEMAFO to print something to our UAT.
So.
So far, our experiment has been.
You know, incrementing our.
Our task profile is with this delay.
I'm going to delete all of our pseudo delay from each and every function, so I delete this first one,
delete this second one.
Delete this third one.
And then there should be a last one to leave this one.
OK, so each task is simply going to take the SEMAFO and imprint's to the serial port and then release
the SEMAFO.
So just like we did in our native apps, I'm going to say, oh, SEMAFO acquire.
And this takes two arguments.
The idea of the semaphore you wish to acquire and then the weeks time we saying wait forever.
So we all get stuck here until we are able to acquire the SEMAFO.
Once we do that, we're going to print this blue task to the new art and we're going to release the
SEMAFO so that the next task will have access to it.
And the next one, which is read is going to acquire the SEMAFO as well.
And then it will do the same thing after red.
Then Orange would acquire the semaphore and we can let Orange and the others we can.
We can pass it around, but let's experiment, we just these two tasks.
OK.
Let's see, what else are we missing?
We are looking good, so I'm going to click here to build.
OK, so because we deleted our.
For int, because we deleted our four inch equals zero less than seven thousand, the delay, who gets
in a warning of having this unused variable here?
I'm going to delete each and every one of them of deleted the one in orange.
I've deleted the one in green.
I'll do that for blue and red.
I'll delete this one here and see.
I would like to read over here as well.
And now let's do it again, click over here to build.
It's built successfully.
All right, click over here.
And then I said, bug us a STEM 32 application also like this over here.
And then I'll say, OK.
It's open in.
Quick to switch.
And then I'm going to open real to.
OK, this is real time from the last time we used it.
I'm going to clear this, going to minimize this and I'm going to click play over here so we can see
how our system is working.
OK, so as you can see, red, blue, red, blue, red, blue, blue.
We already know this.
So now we know how to achieve this using the CMS artist API.
OK, so that's all there is.
And I've seen the next lesson.
Have a nice day.