gpt4 book ai didi

c - pthread_mutex_lock 返回无效参数

转载 作者:太空狗 更新时间:2023-10-29 14:54:11 27 4
gpt4 key购买 nike

我正在编写一些 C 代码,但在锁定互斥体时遇到了问题。该代码调用了一个函数,并且该函数锁定了一个互斥锁以确保文件指针不会被覆盖,这在多个实例中都可以正常工作,可能对被调用函数进行了大约 10-20 次单独调用,但在下一次调用时,pthread_mutex_lock 将返回结果 22。然后我将此结果放入 strerror();并取回无效参数。

无效参数是什么意思,感谢您提供的任何帮助。

最佳答案

22 是ENVAL 错误代码,表示参数无效。确保你已经初始化了你的互斥体,或者如果在某个时候你已经在某处将它单元化了。

还有 man pthread_mutex_lock说:

EINVAL

The mutex was created with the protocol attribute having thevalue PTHREAD_PRIO_PROTECT and the calling thread's priority is higherthan the mutex's current priority ceiling.

我不太明白,但这可能意味着您需要更改线程的优先级。我不知道。也许其他人可以照亮它。

关于c - pthread_mutex_lock 返回无效参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12781944/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com