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 4550246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:28:14+00:00 2026-05-21T16:28:14+00:00

What are the principles of a condition variable in synchronization of the processes of

  • 0

What are the principles of a condition variable in synchronization of the processes of operating systems?

  • 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-05-21T16:28:14+00:00Added an answer on May 21, 2026 at 4:28 pm

    Well, conditional variables allow you to wait for certain condition to occur. In practice your thread may sleep on conditional variable and other thread wakes it up.

    Conditional variable also usually comes with mutex. This allows you to solve following synchronisation problem: how can you check state of some mutex protected data structure and then wait until it’s state changes to something else. I.e.

    /* in thread 1 */
    pthread_mutex_lock(mx); /* protecting state access */
    while (state != GOOD) {
        pthread_mutex_unlock(mx);
        wait_for_event();
        pthread_mutex_lock(mx);
    }
    pthread_mutex_unlock(mx);
    
    
    /* in thread 2 */
    pthread_mutex_lock(mx); /* protecting state access */
    state = GOOD;
    pthread_mutex_unlock(mx);
    signal_event(); /* expecting to wake thread 1 up */
    

    This pseudocode sample carries a bug. What happens if scheduler decides to switch context from thread 1 to thread 2 after pthread_mutex_unlock(mx), but before wait_for_event(). In this case, thread 2 will not wake thread 1 and thread 1 will continue sleeping, possibly forever.

    Conditional variable solves this by atomically unlocking the mutex before sleeping and atomically locking it after waking up. Code that works looks like this:

    /* in thread 1 */
    pthread_mutex_lock(mx); /* protecting state access */
    while (state != GOOD) {
        pthread_cond_wait(cond, mx); /* unlocks the mutex and sleeps, then locks it back */
    }
    pthread_mutex_unlock(mx);
    
    /* in thread 2 */
    pthread_mutex_lock(mx); /* protecting state access */
    state = GOOD;
    pthread_cond_signal(cond); /* expecting to wake thread 1 up */
    pthread_mutex_unlock(mx);
    

    Hope it helps.

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

Sidebar

Related Questions

I understand the principles but i have a hard time seeing where the practical
What are good principles in designing a software library for the use of scientists
According to CSS principles when we want to implement reusability of styles we should
After reading the Service Oriented Architecture Principles site and the respective Wikipedia article I
From what I understand of REST principles, URLs should represent a single resource, like
I'm trying to get the principles of doing jQuery-style function chaining straight in my
Are there any known design principles, best-practices and design patterns that one can follow
Am I right in understanding the principles of DAO & Service layer interconnection? DAO
I'm looking for patterns and principles for using with WPF and NHibernate in model-view-controller
Im new to Web Development and its principles so apologies if my question does

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.