Pthread_cond_wait without while loop

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?
+3
source share
1 answer

The loop is required because according to http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html :

pthread_cond_timedwait() pthread_cond_wait(). pthread_cond_timedwait() pthread_cond_wait() , .

+7

All Articles