Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:29:03+00:00 2026-06-04T01:29:03+00:00

global variable ‘temp’; **threadA** -pthread_mutex_lock- if (temp == ‘x’) -pthread_cond_wait- do this -pthread_mutex_unlock- **threadB**

  • 0
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?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:29:05+00:00Added an answer on June 4, 2026 at 1:29 am

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

    Spurious wakeups from the pthread_cond_timedwait() or pthread_cond_wait() functions may occur. Since the return from pthread_cond_timedwait() or pthread_cond_wait() does not imply anything about the value of this predicate, the predicate should be re-evaluated upon such return.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to reassign a global variable (in this case '$aDoor') by doing
i have a global variable UIColor *textColor; I am update this variable by the
I have a global variable MyGlobalVar and some code that looks like this: var
I'm using a global variable that toggles between true and false on mouse enter
I'm declaring a global variable in my program: double mat[3200][3200]; when passing this array
I have this global variable which is used as counter which I want to
I have a global variable which is an instance of a class. This class
I've declared a global variable class like this: public class globalVar extends Application {
I'm implementing Inter-Thread Communication using global variable. //global var volatile bool is_true = true;
I have a client global variable in javascript. I need to access this global

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.