This was the one of the most puzzling problems I faced. The Teja application we had was failing once in a blue moon printing the message "unlock of mutex failed".
Looking at he code I saw that pthread_unlock_mutex returned an error which should never happen.
I spent a month writing a wrapper for the pthread/mutex library (a mutex is in this particular case a 64-byte memory area, futex was not called).
I put signatures before and after the mutex, checked signatures & various mutex fields before entering the true mutex call to no avail.
It was a random memory corruption that I solved elsewhere so this error ceased to happen.