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

The Archive Base Latest Questions

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

I have a thread pool. The main() function kicks off the classic pool setup.

  • 0

I have a thread pool. The main() function kicks off the classic pool setup. A boss thread and a few worker threads. Most of the code is completed, however the missing part is the error handling.

When an error occurs to one of the boss/worker threads, pthread_exit() is called. How does the main() thread knows that something went wrong in the pool in order to restart it?

  • 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-28T18:18:57+00:00Added an answer on May 28, 2026 at 6:18 pm

    If you want to save error or recovery information, or you want a non-blocking function, you can use a condition variable together with an associated mutex and a structure containing the failing thread, the error and the recovery information you need. All these variables should be global.

    pthread_cond_t cond  = PTHREAD_COND_INITIALIZER;
    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    struct error_info err;
    

    At the boss thread you must first initialize the err structure and then lock the mutex.

    pthread_mutex_lock(&mutex);
    

    Then you wait for a condition to occur using pthread_cond_wait.

    pthread_cond_wait(&cond, &mutex);
    

    After the condition occured you handle the error and you use pthread_join to get the return value from your thread. Note that pthread_cond_wait is blocking, if you want a non-blocking version you should use pthread_cond_timedwait which has a third parameter, a struct timespec *, which hold the absolute system time at which the wait expires. At the end remember to unlock your mutex.

    pthread_mutex_unlock(&mutex);
    

    At the failing worker thread, before exiting you should first lock the mutex, then fill the err structure, signal the boss thread, unlock the mutex and exit. To signal the boss thread you should use the pthread_cond_signal function.

    pthread_cond_signal(&cond);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom thread pool class, that creates some threads that each wait
I have a java application where the main-thread starts 2 other threads. If one
Preliminary : I have an application which maintains a thread pool of about 100
I have a scenario when I start 3..10 threads with ThreadPool. Each thread does
Suppose I have thread 1, the main window UI thread and thread 2, a
I have some thread-related questions, assuming the following code. Please ignore the possible inefficiency
I am comparing a task queue/thread pool pattern system to an n -threads system
I've created a pool of 4 worker threads to process some files. In the
I'm using Thread::Pool::Simple for multi-threading. I have a couple of questions which are quite
I have a manager class that produces tasks for a threadpool, and each thread

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.