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
吗? - 如果我们不需要循环,另一种编写代码的方法是什么?
- 这是编写代码的正确方法吗?