[Autogenerated] The next object I'd like to discuss,
is a critical section, a critical section,
is not a kernel object.
In fact, it's a user mode object.
It doesn't have any kind of kernel representation really.
However, it is very useful.
So it's worth talking about the purpose of a critical section,
is to do exactly what the tex does or at least something very close.
To it but it is a usable replacement doesn't use a
kernel object behind the scenes.
This means that It has one advantage.
And several disadvantages.
The basic idea, is that It works just like a tex,
its purpose, is to make sure only 31 thread at a time can acquire it.
And move into some critical region where it accesses some shared
data That's the purpose of the critical section.
It's exactly the same as a tex in that respect.
However, because it is a data structure in users space,
it cannot be shared with multiple processes.
So it's limited to working within the same process, meaning it's there.
To synchronize threads running within the same process.
And the way to define a critical section,
is to define this structure, critical section,
then use an API I over it.
The advantage of using critical section.
Is simply that of performance because it's not a true, kernel object.
It doesn't have the overhead of user two kernel transition.
That occurs with the tex and If there's no contention on the critical section,
which is more common than not then There's no transition,
to kernel mode simply input it.
Is just cheaper in terms of its performance.
So you want to use that when you need to synchronize threads,
in the same process, to access some shared data in a synchronized fashion,
and because it's not a kernel object.
It has its own specialized API an critical section,
to try, to acquire the critical section.
And block if you can't acquire it right now.
And left critical section, is the opposite.
So you can think of an critical section as the equivalent of wasteful
single object on the TEX and lift critical section,
is the equivalent of release TEX.
However, the another downside to a critical section.
There's no way.
To specify any time out other than infinite or zero.
With the MU attack we have the flexibility.
To provide some time out which can be any number of
milliseconds with the critical section.
The an critical section function waits indefinitely until
the critical section becomes available.
Zero time.
Is also possible.
To achieve by using another API I called try enter critical section.
Another difference between a critical section.
And the tex is that There's no notion.
Of an abandoned critical section because the kernel is not aware of an
existence of such an object called the critical section.
So if a thread, call an critical section, then dies.
For whatever reason,
we have a deadlock on our hands because all other threads waiting
for the critical section will wait indefinitely.
Let's see how to replace a mute text with a critical section in our next demo.