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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:12:45+00:00 2026-05-27T18:12:45+00:00

To quote the man page: When using condition variables there is always a Boolean

  • 0

To quote the man page:

When using condition variables there is always a Boolean predicate involving shared variables associated with each condition wait that is true if the thread should proceed. 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.

So, pthread_cond_wait can return even if you haven’t signaled it. At first glance at least, that seems pretty atrocious. It would be like a function which randomly returned the wrong value or randomly returned before it actually reached a proper return statement. It seems like a major bug. But the fact that they chose to document this in the man page rather than fix it would seem to indicate that there is a legitimate reason why pthread_cond_wait ends up waking up spuriously. Presumably, there’s something intrinsic about how it works that makes it so that that can’t be helped. The question is what.

Why does pthread_cond_wait return spuriously? Why can’t it guarantee that it’s only going to wake up when it’s been properly signaled? Can anyone explain the reason for its spurious behavior?

  • 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-27T18:12:45+00:00Added an answer on May 27, 2026 at 6:12 pm

    The following explanation is given by David R. Butenhof in “Programming with POSIX Threads” (p. 80):

    Spurious wakeups may sound strange, but on some multiprocessor systems, making condition wakeup completely predictable might substantially slow all condition variable operations.

    In the following comp.programming.threads discussion, he expands on the thinking behind the design:

    Patrick Doyle wrote: 
    > In article , Tom Payne   wrote: 
    > >Kaz Kylheku  wrote: 
    > >: It is so because implementations can sometimes not avoid inserting 
    > >: these spurious wakeups; it might be costly to prevent them. 
    
    > >But why?  Why is this so difficult?  For example, are we talking about 
    > >situations where a wait times out just as a signal arrives? 
    
    > You know, I wonder if the designers of pthreads used logic like this: 
    > users of condition variables have to check the condition on exit anyway, 
    > so we will not be placing any additional burden on them if we allow 
    > spurious wakeups; and since it is conceivable that allowing spurious 
    > wakeups could make an implementation faster, it can only help if we 
    > allow them. 
    
    > They may not have had any particular implementation in mind. 
    
    You're actually not far off at all, except you didn't push it far enough. 
    
    The intent was to force correct/robust code by requiring predicate loops. This was 
    driven by the provably correct academic contingent among the "core threadies" in 
    the working group, though I don't think anyone really disagreed with the intent 
    once they understood what it meant. 
    
    We followed that intent with several levels of justification. The first was that 
    "religiously" using a loop protects the application against its own imperfect 
    coding practices. The second was that it wasn't difficult to abstractly imagine 
    machines and implementation code that could exploit this requirement to improve 
    the performance of average condition wait operations through optimizing the 
    synchronization mechanisms. 
    /------------------[ David.Buten...@compaq.com ]------------------\ 
    | Compaq Computer Corporation              POSIX Thread Architect | 
    |     My book: http://www.awl.com/cseng/titles/0-201-63392-2/     | 
    \-----[ http://home.earthlink.net/~anneart/family/dave.html ]-----/ 
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Even though the linux man page for wait 1 explains very well that you
The man page for nice says "nice() adds inc to the nice value for
I've so far dabbled in Flash doing 1-man shows for quite some time, but
Quote from Wikipedia : A public key token. This is a 64-bit hash of
Quote from Head first html: You can add padding to the top and bottom
Quote from Jason Coco it not possible to set multiple in UILabel... but how
Quote from hib official docs: Starting with version 3.0.1, Hibernate added the SessionFactory.getCurrentSession() method.
To quote wikipedia: Scrum is facilitated by a ScrumMaster, whose primary job is to
To quote Wikipedia : Two commonly used languages that support many kinds of implicit
I saw this quote on the question: What is a good functional language on

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.