Mutex problem

Hi everybody,

I have a program mutex problem between two threads (one thread in the main function and the other in a thread function). I have a global mutex who create in the thread function (CreateMutex) because I want that this thread owns the mutex first. When mutex is released the main function get it and works. The problem is that the main function thread is waiting for the thread forever although the other thread have already released.

have you any ideas?

Thank you
check that before exiting the mutex section is the mutex released?
your flow is blocking on the mutex this means the thread which acquired the mutex before it has not released it..

one of the major causes of deadlock is this:

1
2
3
4
5
6
7
8
9
10
pthread_mutex_lock()

...some code...

if(condition)
{
return error;
}

pthread_mutex_unlock()


i've taken an example of pthreads but this is a general thing. you have unlocked the mutex before exiting but if your code returns from if statement then it will not be unlocked and you have a dead lock.
I assume the thread has initialized the mutex before the main program calls pthread_mutex_lock() on it.
Topic archived. No new replies allowed.