Hiten Pandya wrote:
> hi all,
> sorry for running -current.. but i am an enthusiastic
> and challenging man...(boy)...
> anyways.. whats a mutex and a lock order reversal...
> if you could point to some good manual on these
> subjects... thanks...
> help is appreciated...
> thanks again...

A mutex is an algorithmic object used to serialize operations.  It
stands for ``mutual exclusion''.  It's useful when the same code is ran
several times in parallel.  For example, if two threads wanted to modify
a linked list in the same time, there is a chance that the linked list
would get corrupted since an insert or remove operation is not atomic
(one of the thread could get preempted when it has not finished to
remove or insert an element, and thus the linked list is not in a normal

In such cases, every part of the code that modify the linked list has to
obtain the mutex before doing it and release after.  If another thread
tries to acquire the mutex, it will block until the first thread has
released it.

When some code has to obtain two locks or more, deadlocks might happen.
If thread 1 has lock A and tries to acquire lock B while thread 2 has
lock B and wants lock A, then both threads will block indefinitely.  To
solve this, one way is to always obtain the lock in the same order.  The
warning messages you got show that some code is violating this lock
order somewhere.

I found ``Unix Internals'' from Uresh Vahalia to be a very good book on
this topic.

Hope this helps,
Maxime Henrion
Don't be fooled by cheap finnish imitations ; BSD is the One True Code

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to