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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:34:56+00:00 2026-05-28T20:34:56+00:00

i have a problem with boost condition, i have these two instance variable within

  • 0

i have a problem with boost condition, i have these two instance variable within a cpp class:

boost::condition          wait_answer_condition;
boost::mutex              wait_answer_mutex;

then i have a method that send a message and with on condition:

method1

boost::unique_lock<boost::mutex>  lock(wait_answer_mutex)

//do some work and send message

//wait the result
wait_answer_condition.wait(lk);

//get the result
result = responseIdSyncMap[currentRequestID];

then i have another method that receive the result and wakeup the sender thread

method2

int requestID = responseData->getInt32Value("response_id");
responseIdSyncMap.insert(make_pair(requestID, responseData));
wait_answer_condition.notify_one();

the two method are called in different thread. The problem is that when the method2 is called the wait_answer_condition is release before “wait_answer_condition.notify_one()” is called, and the method1 is awaked without found the result.

Anyone has an idea about that?

  • 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-28T20:34:57+00:00Added an answer on May 28, 2026 at 8:34 pm

    Condition variables can wake up spuriously, and wake-up events are generally not stored (i.e. a wake-up that is issued before anyone is waiting for it is lost like a handclap in a wood when noone is there to hear). Therefore, condition variables are almost always used in a loop:

    bool is_answered = false;
    
    // method1
    boost::lock_guard<boost::mutex> lock( wait_answer_mutex );
    while ( ! is_answered )
        wait_answer_condition.wait(lock);
    
    // method2
    boost::lock_guard<boost::mutex> lock( wait_answer_mutex );
    is_answered = true;
    wait_answer_condition.notify_one();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the following code: #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <iostream>
I have a problem with the boost::asio::serial_port class reading from a GPS device (USB-Serial).
I have the following situation: I create a boost::thread_group instance, then create threads for
i have little problem with boost::asio library. My app receive and process data asynchronously,
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I'm new in using boost and have a problem. I need shared_mutex function in
I've almost completely installed Boost, but I have a problem with how to set
I have a problem using boost serialization using binary archives. It works when using
I have the following problem. I have to implement a class that has an
I faced a problem using a Boost variant. I have a segmentation fault when

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.