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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:00:51+00:00 2026-06-12T10:00:51+00:00

Imagine a thread blocks on a condition variable: pthread_mutex_lock (mutex); do_something (); pthread_cond_wait(cond, mutex);

  • 0

Imagine a thread blocks on a condition variable:

pthread_mutex_lock (mutex);
do_something ();
pthread_cond_wait(cond, mutex); // [1]
do_something_else ();
pthread_mutex_unlock (mutex);

The mutex is unlocked and a different thread trying to lock the mutex is unblocked:

pthread_mutex_lock (mutex);
do_some_work ();
pthread_cond_signal (cond);
pthread_mutex_unlock (mutex);

At the same time there’s another thread waiting to acquire the ownership of the critical section:

pthread_mutex_lock (mutex); // [2]
do_some_random_work ();
pthread_mutex_unlock (mutex);

Now, the question is: When pthread_cond_signal() is called, is it guaranteed that the pthread_cond_wait() [1] will unblock before pthread_mutex_lock() [2]?

The POSIX specification seems to say nothing about the case.

  • 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-12T10:00:52+00:00Added an answer on June 12, 2026 at 10:00 am

    No, it’s not.

    Descriptions of pthread_cond_signal() are sometimes worded as

    When each thread unblocked as a result of a pthread_cond_signal() or pthread_cond_broadcast()
    returns from its call to pthread_cond_wait() or pthread_cond_timedwait(), the thread owns the
    mutex with which it called pthread_cond_wait() or pthread_cond_timedwait(). The thread(s)
    that are unblocked contend for the mutex according to the scheduling policy (if applicable),
    and as if each had called pthread_mutex_lock().

    (Taken from this link)

    As you can see, it’s worded as “as if each had called pthread_mutex_lock()”. Thus, there is no priorization of this implied pthread_mutex_lock call compared to an actual pthread_mutex_lock call from another thread.

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

Sidebar

Related Questions

I was trying to built atop the thread here: Variable length template arguments list?
Ok, imagine a typical scenario, - there is a thread object and comments, attached
Imagine a table with a thread of messages that fills the page - the
Imagine a producer-consumer scenario, thread A produces entries, one to many other threads consume
Let's imagine I have two threads which execute some database-oriented code in thread-specific TransactionScopes
What approaches do exist to execute some code on specified thread? So let's imagine
I'm working on a realtime imaging system. UI thread: grabs images from a camera
Imagine a cube-shaped piece of Swiss cheese. We model the cheese through a 20x20x20
imagine this html on a page <div id=hpl_content_wrap> <p class=foobar>this is one word and
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'

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.