[Asterisk-Dev] MUTEX definition
Race Vanderdecken
asterisk at vanderdecken.com
Wed Dec 15 09:03:27 MST 2004
Mutex mean mutual exclusion.
It is a point in the code where access to Resources ( memory, code, or
data structures ) are given exclusive access. On a limited number of
threads can access that point in the code or the memory protected by the
code.
Example.
You and your wife own one car and only one key for your car, but each of
you wants to drive the car.
The car key is the MUTEX. In order to drive the car you must have the
key.
A MUTEX makes the code/thread wait until it can get the car key before
can continue.
The code/thread you are running is waiting to cross a MUTEX is blocked
from running until your wife returns the car key to the key peg in the
house, then you can pick up the car key and do your thread errands.
If your wife wants to use the car she is then "blocked" until you return
with the car key and put it back on the peg.
Others maybe waiting for the car key, your children or parents, and they
could be ahead of you in the line. You must wait for the other "threads"
to get their turn before you can have the car key.
Deadlocks can occur with MUTEX's if you are not careful.
Lets say you also have a trailer and you want to use both the car and
the trailer at the same time. So you wait to get the car key and then
wait to get the trailer. When you have both you can go on vacation.
But what if someone else wants the car and the trailer but they ask for
the trailer first and then they try to get the car key. Meanwhile you
have the car key and want the trailer.
Now, because of the order of events and because threads can be
interrupted at anytime except in an Atomic function (further reading
involved, but an Atomic function can't be switched out off of the
CPU...) you have the key but your brother in law has the trailer. You
can't get the trailer until he lets go and he can't have the car until
you let go of the car key. This is deadly embrace, neither can continue
and the threads lock up.
It is important to ask for resource in the correct order. That way
whomever gets the car key first can have the trailer if they want it.
But the thread/person that needs both must ask for the car key first and
then is allowed to ask for the trailer.
Does this help?
Are you asking about a specific line in the * source code?
Race "The Tyrant" Vanderdecken
"In the Land of the Blind the One-eyed man is Elvis"
-----Original Message-----
From: asterisk-dev-bounces at lists.digium.com
[mailto:asterisk-dev-bounces at lists.digium.com] On Behalf Of Angel Diaz
Sent: 15 December 2004 10:22
To: asterisk-dev at lists.digium.com
Subject: [Asterisk-Dev] MUTEX definition
Hi,
Does somebody can explain/tell me what is the word MUTEX referred to
in
the * source code ?
Thanks,
Angel.
_______________________________________________
Asterisk-Dev mailing list
Asterisk-Dev at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
More information about the asterisk-dev
mailing list