I am working on some C code and am having a problem with locking a mutex. The code does a call to a function and this function locks a mutex to ensure a file pointer doesn\'
Sounds like you have a threading problem or a wild point somewhere else in your program. Try printing the value of the mutex pointer. Try having another thread that simply locks the mutex and then prints to a log file the time and that the lock was successful, then unlocks the mutex. I suspect the problem is not where you are looking.
Also, as other have said here, your best bet is to create a very small test program that demonstrates the problem and post it here. Chances are you won't be able to get that small program to demonstrate the error. Then slowly add all of your original code into the small program until the error returns. If it returns, you now know what caused the problem. If it doesn't return, you're done.
22 is ENVAL
error code which means invlalid argument. Make sure that you have initilized you mutex, or if at some point you have unitilized it somewhere.
Also man pthread_mutex_lock says:
EINVAL
The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling.
I don't quite understand this but it probably means that you need to change thread's priority. I am not sure. Maybe someone else can shine light on it.