[Autogenerated] Let's now turn our attention.
To a tex, and the tex is an kernel object type, that allows mutual exclusion.
Essentially, it means that only one,
third at a time can acquire the tex and make forward
progress in kernel terminology.
You might see the name mutant being used.
It's the same thing, and Therefore, compatibility reasons.
And the basic idea,
is that only one thread can acquire the TEX at the
same time no matter how many threads,
are trying to acquire the TEX at the same time.
Only one can succeed.
And the others will wait.
And then the thread will enter a piece of code that should access some shared
data and This is sometimes referred to as a critical region,
just a piece of code that only one thread at a time should be
running because that piece of code is accessing some shared data
We're trying to protect against data races.
So in Tex purpose, is to protect against data races the threat.
That managed to get the MU tax is Now becoming the owner of the
Mu tax and that means that its the only one,
that can release the Mu attack and Once it does that when its done
working with the shared data another thread,
that might be waiting on the tex can acquire it but
only One of course another thing, that is a property of a mute tax,
is that You can acquire it recursively by the same thread.
And it's going to succeed automatically.
Incrementing some counter internally, and that makes sense because that thread,
is already the order of the mu tax,
which means it can acquire it again if needed.
You might be wondering why it is that useful.
It really depends on the functions.
That you have in your code you might have one function calling another function.
That needs the tex, and Both of them need that same TEX.
So it's OK.
To acquire it recursively because in other cases,
that other function might be called directly and So,
that means that this ownership concept, is very important for Tex.
In fact, its the only object.
That maintains this kind of concept when the thread acquires the mut text,
its the owner of the mut text.
That's the only one thread,
that can release it other threads if they try to release the mut,
they don't own.
This simply fails.
Here's the consensual view of using a TEX,
let's say we have two threads, that want to access the same data from time,
to time, to time.
Normally they're running independently and work on
different data So there's no need.
To synchronize anything but still from time,
to time they need to access some shared data may be a link list.
So once that happens, each thread will try.
To acquire that Tex, that is used to protect,
that shared data only one of them can succeed.
There's no way for both of them.
To succeed.
That's guaranteed by the tex behavior Let's assume thread,
T one manage, to get the mut text, and thread T two.
On the other hand,
will have to enter a weight state without burning any CP cycles.
Now,
T one can access the shared data by continually running its code When it's done,
it's going to release,
that mut tax because it's done working on the shared data and then T,
two has the option of acquiring the mut.
Check It will require the mut text assuming no other reds,
are fighting over the Tex and then that thread can go ahead and
access the shared data and This is where the critical region is
that time between the acquisition.
And the release of the MUT, attack where the shared data is being accessed.
And Of course,
you want to make sure you acquire the mutt for as short time as possible.
Because if you're only acquiring the tex all the time,
you're essentially killing concurrency.
And So the assumption is that T one,
and T two here can do things differently running on different
code using different data most of the time,
but not all of the time.
And when they need to synchronize, that the shared data doesn't get corrupted.
So we don't get a database They will need to acquire that Tex.
So obviously,
while T two is working on the shared data the T1 thread can
work on other stuff which have nothing to do with the shared
data So that's a Very simple example.
Let's see, a code example, using a tex.