【发布时间】:2012-05-22 15:32:39
【问题描述】:
global variable 'temp';
**threadA**
-pthread_mutex_lock-
if (temp == 'x')
-pthread_cond_wait-
do this
-pthread_mutex_unlock-
**threadB**
-pthread_mutex_lock-
if (someCondition == true)
temp = 'x'
-pthread_cond_signal-
-pthread_mutex_unlock-
就我而言,我可能没有任何循环,我只有一个 if 条件。所以,我希望当 temp == 'x' 时,threadA 应该这样做/这个。
- 在处理
pthread_cond_wait时是否必须使用循环? - 如果我们不需要循环,编写代码的另一种方法是什么?
- 这是一种正确的代码编写方式吗?
【问题讨论】:
标签: multithreading pthreads mutex condition-variable