As from Here:
A deadlock requires four conditions: mutual exclusion, hold and wait, no preemption, and circular wait.
It does not matter matter if you use a unique lock or normal lock, any waiting operation which fulfills the four conditions can cause a deadlock.
The current code does not fulfill the deadlock conditions
As @Mestkon has pointed out in the comments, in your code every thread currently uses only one mutex, thus it is impossible to fulfil the "hold and wait" condition. Thus no deadlock can happen.
Define a locking sequence
A usually simple practical approach is to define a locking sequence and use it everywhere.
For example if you ever need mutex1
and mutex2
at the same time, make sure to always lock mutex1
first, then mutex2
second (or always the other way around).
By that you can easily prevent the "circular wait" (mutex1
waiting for mutex2
and mutex2
waiting for mutex1
) condition, thus no deadlock can happen.