Hello, welcome back.
In this lesson, we go going to see how to resume a thread just like we saw in our native free ARTUS
API lessons.
So we suspended a thread.
We created this global variable here called Suspend Monitor.
I'm going to cut this and bring it to the top.
And I'm going to also create two other variables.
We would have one code resume monitor in another one called suspended.
This will be set to true if it's suspended or not.
It starts off as false because we've not suspended a thread yet.
OK, and to use the Boolean, we need to include SDD Booth H, otherwise we'll receive an error.
So I'm going to include that age over here.
OK, so we have these variables, so spend money to resume monitor suspended.
OK, so let's go back to the bit where the task gets suspended.
The red a little controller task is the one doing the suspension.
So what happened is we kept incrementing suspend monitor.
And when it became greater than when it became greater than we call it 49, we we suspended blue.
This is a confusing way of writing it, rather than, say, greater than or equal to, I'll simply say,
if it is equal to 50, suspend.
So equal to, equal to and then 50 here, OK?
So we are familiar with this next one we want to do is we want to set the flag suspend flag.
Before we suspend blue, actually, we want to suspend flights here to try to indicate that, OK, we've
suspended and we want to reset the suspend monitor to zero.
OK.
Like this.
OK, so then we're going to have the Orange Thread Monitor for resumption the orange thread over here,
which is below here, is going to also check if suspend is such a true.
So over here, like we did earlier, we say if unaskable suspend it, we open and close it, suspend
it, then we start counting for the time we ought to resume.
And we do this by increments and the resumption the resume monitor and we can see if resume monitor
equals two hundred, then we want to resume.
So over here, just like we did earlier, I can see if resume monitor equals two hundred, then we want
to call our always threat resume function.
Two, we can call it to resume the blue thread, OK?
And we also have to reset our resume monitor and said suspend back to force.
OK.
And of course, we can use semaphores to achieve this, but we using our own control variables.
OK, so this what we have, let's build and see where we get a click over here to build.
It's building.
It's built successfully.
I'm going to right click over here.
And debuggers.
Estimated to cortex in.
iSelect, 38 Aubagio.
And OK.
It's open in.
Switch.
It's loading, and then I'll click to run.
Something happened, live expressions, see?
OK, something happened.
I'm going to stop this.
Let's go back in our collective book.
Switch over here.
OK, I'm going to click here to run, we see all of them incrementing as soon as we hit fifty one.
Blue task is frozen.
And then let's see, did he ever get resumes so it gets resumed quickly and then it's incremented by
one?
OK, and if we want to observe further, we can.
We can add our suspend monitor.
Also, spend money to and resume monitors, we can add them over here.
This is resume monitor.
This is suspend monitor.
OK, so let's run.
OK, resume monitor as soon as it hits two hundred.
The task resumes, OK, so it's working as expected and of course, we've seen this before, so we expected
nothing apart from this.
That's all there is.
I'll see you later.
Have a nice day.