gpt4 book ai didi

c - 互斥锁上的随机错误

转载 作者:行者123 更新时间:2023-11-30 15:10:23 24 4
gpt4 key购买 nike

互斥锁随机成功或失败,失败时会出现以下情况:

Invalid argument

tpp.c:62: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= __sched_fifo_min_prio && new_prio <= __sched_fifo_max_prio)' failed.

代码非常基本,您可以在此处看到:

pthread_mutex_t mutex;
main() {
int ret;
pthread_mutexattr_t attr;
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
ret = pthread_mutex_init(&mutex, &attr);
if (ret != 0) {
printf("pthread_mutex_init\n");
return 1;
}
ret = pthread_mutex_lock(&mutex);
if (ret != 0) {
printf("mutex_lock failed %s\n", strerror(ret));
return 1;
}
ret = pthread_mutex_unlock(&mutex);
if (ret != 0) {
printf("mutex_unlock failed %s\n", strerror(ret));
return -1;
}

这是为什么?

最佳答案

您没有初始化attr。其内容未定义。

参见pthread_mutexattr_init :

DESCRIPTION

The function pthread_mutexattr_init() initialises a mutex attributes object attr with the default value for all of the attributes defined by the implementation.

关于c - 互斥锁上的随机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36221574/

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