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 any loops, I just have an if condition. So, I want that when temp == ‘x’, then the threadA should do that/this.
- Is the loop compulsory when dealing with the
pthread_cond_wait? - What is the other way for writing the code if we don’t need loops?
- Is this a correct way of writing the code?
A loop is compulsory because according to http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html: