I am doing C++ multithread programming. I use mutex to read and write a queue in order to avoid deadlock. Currently, I only launch 1 thread for
pthread_mutex_lock(&the_mutex);
But, in GDB, my code is frozen here, it is pending.
Why ? there is only one thread !!!
thanks
From the
pthread_mutex_lock()manual page:Bottom line: it’s perfectly possible to cause a deadlock with only one thread if you try to lock a mutex that is already locked.
In case you are wondering, on Linux
PTHREAD_MUTEX_DEFAULTis usually a synonym ofPTHREAD_MUTEX_NORMAL, which in turn is what is used in the default mutex initializer.