pthread:avoid deadlock case 1

Always trying to obtain the locks use the same
order.
pthread: avoid deadlock case 2

The best implementation is to use trylock()
and release any resource if trylock() fails
to lock on.