Let's say I have two variables,
int x = protected_var1 + protected_var2;
pthread_mutex_unlock(&mutex1); //Does the order of the next two lines matter?
I cannot for the life of me figure out how a deadlock could result from this though if the locks are always obtained in the same order wherever both are used.
In these circumstances, I don't think the order of unlocking the mutexes could be the cause of a deadlock.
pthread_mutex_unlock() doesn't block, both mutexes would always get unlocked regardless of the order of the two calls.
Note that if you attempt to acquire any locks between the two unlock calls, this can change the picture completely.