问题描述
我工作的一些C code和我有带锁紧互斥的问题。在code做了调用一个函数,这个函数锁定一个互斥体,以确保文件指针没有被覆盖,这工作正常的几个实例,可能被调用的函数约10-20独立的电话,但下一次调用,将调用pthread_mutex_lock与22的结果返回,然后我把这个结果成字符串错误();而回来无效的参数。
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't get overwritten, this works fine for several instances, probably about 10-20 separate calls of the function being called, but on the next call, pthread_mutex_lock will return with a result of 22. I've then put this result into strerror(); and got back invalid argument.
这是什么无效的参数手段,感谢您的帮助,您可以提供。
What does invalid argument means, thanks for any help you can provide.
推荐答案
听起来像是你有一个线程问题或野生点的别的地方在你的程序的。尝试打印互斥指针的值。尝试有另一个线程只是锁定互斥锁,然后打印到一个日志文件的时间和锁成功,然后解锁互斥量。我怀疑问题是不是你正在寻找。
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.
此外,其他在这里说,最好的办法是创建一个展示这个问题一个非常小的测试程序,并张贴在这里。有可能到头来你将无法得到小程序来演示错误。然后慢慢加入所有你原来的code进入小程序,直到错误再次出现。如果返回,你现在知道是什么引起的问题。如果不回来,你就大功告成了。
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.
这篇关于返回的pthread_mutex_lock无效的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!