From the pthread_mutex_lock()
manual page:
If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall
not be provided. Attempting to relock the mutex causes deadlock. If a
thread attempts to unlock a mutex that it has not locked or a mutex
which is unlocked, undefined behavior results.
If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively
lock the mutex results in undefined behavior. Attempting to unlock the
mutex if it was not locked by the calling thread results in undefined
behavior. Attempting to unlock the mutex if it is not locked results
in undefined behavior.
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_DEFAULT
is usually a synonym of PTHREAD_MUTEX_NORMAL
, which in turn is what is used in the default mutex initializer.