[Autogenerated] In this example, we're using a T text within the same process,
which means it doesn't have any particular advantage over critical section.
We're also using the infinite time out here again,
which means that critical section can definitely replace the MUT text here.
So let's just go ahead.
And do that instead of the H lock here, which is our mut,
attack I'm going to change, that to a critical section.
Let's call that CS,
and Now we need to change the a P I in order to work with the critical section.
So instead of waiting for a single object we're going to call enter
critical section providing the critical section here,
and instead of release be its going to call the opposite function.
Wi leave critical section.
By the way, it would be a Good idea.
To use drive Finally, as we discussed in previous modules,
I'm not going to do that to keep the code simple.
But this is something you should be doing.
And that goes of course for the T text as well.
So any time we're going to use the new text.
We're going to replace that with the same kind of code enter critical section.
And leave critical sections.
Of his enter and here's ee the only thing left,
to do here, is to create or to initialize critical section,
data structure, is already there as a global variable,
but you still need to initialize that using the
function initialize critical section.
And technically the opposite function of that which would be
the opposite of trying to close a handle.
In fact,
we didn't close the L2 Tex earlier which we should have done to make it uh
like better or at least look uh complete we can Go ahead.
And Use delete critical section, to delete the critical section.
So let's try it out.
The other things should be working just as before we
don't get any corruptions or crashes.
I'll leave it,
up to you to Try it out without a critical section or without a tex,
and See what happens in that case, but obviously things continue,
to work as before.
So critical section,
is very useful and especially when you just need to synchronize very
simply threads running within the same process.
If you do that with different processes like in the tes example,
we did in the previous module a critical section,
is irrelevant.
And simply cannot be used because the critical section
cannot be shared between processes.