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-
In my case, I may not have cycles, I just have an if condition. So, I want that with temp == 'x', threadA should do this / this.
- Is a cycle required when working with
pthread_cond_wait? - What is another way to write code if we don't need loops?
- Is this the right way to write code?
source
share