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

  • Home
  • SEARCH
  • 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 7820557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:20:24+00:00 2026-06-02T07:20:24+00:00

I have problem with this simple wrapper of mutex / cond wait class. I

  • 0

I have problem with this simple wrapper of mutex / cond wait class.
I use it to protect queue of connected clients and to notify threads in the wait state that there are new clients connected, but application crashed with Segmentation Failed at

client_socket_fd = clients_for_threads_q.front();

when its is under stress test only (many clients connected )

Wait at the thread:

    MUTEXCONDSIGNAL_for_workers.lock();
    if ( clients_for_threads_q.empty() )
    {
        MUTEXCONDSIGNAL_for_workers.wait_signal();
    }

    client_socket_fd = clients_for_threads_q.front(); // CRASHED !!!!
    clients_for_threads_q.pop();
    MUTEXCONDSIGNAL_for_workers.unlock();

of course clients_for_threads_q ptotected on writing

    MUTEXCONDSIGNAL_for_workers.lock();
    clients_for_threads_q.push (client_socket_fd);
    MUTEXCONDSIGNAL_for_workers.send_signal();
    MUTEXCONDSIGNAL_for_workers.unlock();
  • 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-02T07:20:26+00:00Added an answer on June 2, 2026 at 7:20 am

    pthread_cond_wait can have spurious wake ups.

    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_wait() or pthread_cond_timedwait() functions may occur. Since the return from pthread_cond_wait() or pthread_cond_timedwait() does not imply anything about the value of this predicate, the predicate should be re-evaluated upon such return.

    You need to change your waiter if condition to a loop:

    while ( clients_for_threads_q.empty() )
    {
        MUTEXCONDSIGNAL_for_workers.wait_signal();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've wrote this simple piece of code. And I have a slight problem with
This seems like a simple problem: I have a WF4 activity that guides the
I have a simple problem with XML got from database. Now, this XML can
I'm guessing this is a simple problem, but I'm just learning... I have this:
I have built a variety of little scripts using Ruby's very simple Queue class,
The Code I have this problem, I am trying to create a simple rectangle
I have problem and i don't know how to solve this simple, i have
I would like to actually use this wrapper, but the problem is i don't
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
Hi i have problem with this code, i found it on the internet and

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.