我有一个问题。如果q->mutex
必须是sem_t
pthread_cond_wait
while(q->thread_lock[pom] < 0)
pthread_cond_wait(&(q->cond), &(q->mutex));
q->pthread_unlock[pom]--;
现在 q->mutex
是 pthread_mutex_t
,但这必须是 sem_t
。
结构体
typedef struct{
int *thread_lock;
int *thread_unlock
pthread_mutex_t mutex;
pthread_cond_t cond;
}q
我想这样做:
typedef struct{
int *thread_lock;
int *thread_unlock
sem_t mutex;
pthread_cond_t cond;
}q
最佳答案
您不能将 sem_t
与 pthread_cond_wait()
一起使用,它需要 pthread_mutex_t
。
从根本上讲,互斥体/条件变量范例与信号量的范例不同 - 像这样将它们组合起来没有任何意义。我建议发布一个新问题来描述您要解决的根本问题。
关于c - 如何更改 pthread_cont_wait 中的互斥体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56621878/