zahra
zahra

Reputation: 175

How to trace code to find out which mutex causes problem

I have some code with many functions and threads and many different mutexes. Some times the code works well and some times I get one of these errors

1) "/usr/include/boost/thread/pthread/mutex.hpp:111: boost::mutex::~mutex(): Assertion '!res' failed."

2) "/usr/include/boost/thread/pthread/condition_variable.hpp:168: boost::condition_variable_any::~condition_variable_any(): Assertion '!pthread_mutex_destroy(&internal_mutex)' failed."

I thought maybe one of the mutexes is getting destroyed before it is unlocked. So, I investigated all the pthread_mutex_destroys in the destructors, but can't find any problem.

For example one of the destructors is as bellow

~class1(){ 
// unlock threads waiting at push or pop
pthread_mutex_lock(&mutex);
pthread_cond_signal(cv1);
pthread_cond_signal(cv2);
pthread_mutex_unlock(&mutex);

// wait for threads blocked in push or pop to exit
while(number_of_threads>0){
usleep(100);
}

//wait them to exit and destroy cv and mutex 
pthread_mutex_lock(&mutex);
pthread_cond_destroy(&cv1);
pthread_cond_destroy(&cv2);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
}

The number_of_threads increases and decreases in the push and pop functions which use the mutex and the condition variables.

How can I trace the code to find out where and why the problem occurs. I have many mutexes and functions so it is not an easy job to find the problem. Any hints will help.

Thanks in advance

Upvotes: 1

Views: 460

Answers (0)

Related Questions