I'm writing a program in C and which has 3 functions in it, A, B and C. I have a static mutex as global which is locking access to these functions. The functions A, B and C and be called in any order from multithreads so, my code looks as follows:
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int A() {
pthread_mutex_lock(&mutex);
... do some processing...
pthread_mutex_unlock(&mutex);
return anInt;
}
int B() {
pthread_mutex_lock(&mutex);
... do some processing...
pthread_mutex_unlock(&mutex);
return anInt;
}
int C() {
pthread_mutex_lock(&mutex);
... do some processing...
pthread_mutex_unlock(&mutex);
return anInt;
}
What might be causing the deadlock?