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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:14:12+00:00 2026-06-15T21:14:12+00:00

I have to write a C application that posts info on web using CURL.

  • 0

I have to write a C application that posts info on web using CURL. The application must run up to N (let’s say 10) requests in parallel at most. How can I wait for ANY thread to finish, rather than specific thread using pthread_join().

I read about pthread_cond_wait, but most examples are how the control thread (main) wakes up a worker thread. I need just the opposite – worker threads must be able to signal/wakeup parent thread before exiting.

Update: Actually I need a way to make manager thread sleep and when a worker thread finishes it’s job it should wake the manager thread to give it another job. It doesn’t matter if the thread will end and new thread will be created for the job or thread pool will be used. Threre still needs to be a way to signal the manager that a job is finished.

I hope that I DON’T get this suggestion:

while(asleep){
  for(i = 0; i< threadCount; i++){
    pthread_mutex_lock(mutex);
    if(threads[i] == IDLE_STATE)
      startNewJob();
    pthread_mutex_unlock(mutex);
    usleep(100*1000);
  }
}
  • 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-15T21:14:13+00:00Added an answer on June 15, 2026 at 9:14 pm

    Condition variable are what you’re after. They can be used just as easily to signal the manager thread from the worker thread as vice-versa.

    Your strawman example at the end is actually very similar to what you could do using a condition variable:

    pthread_mutex_lock(&mutex);
    while (!finished) {
      for(i = 0; i < threadCount; i++) {
        if(threads[i] == IDLE_STATE)
          startNewJob(i);
      }
    
      /* Not finished, and no idle threads, so wait */
      if (!finished)
        pthread_cond_wait(&cond, &mutex);
    }
    pthread_mutex_unlock(&mutex);
    

    When a thread is done, it would simply do:

    pthread_mutex_lock(&mutex);
    threads[self] = IDLE_STATE;
    pthread_cond_signal(&cond);
    pthread_mutex_unlock(&mutex);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an application that is able to write posts from the command
I have to write an application that implements a secure connection between client and
I have to write a C++ application that reads from the serial port byte
I have to write a C# application that works with a SQL server database
I have been asked to write an application that is going to act as
I have to write a SNMP module which monitor a certain server application that
I have an application that write data in the programdata folder in vista. The
I have to write an application where I retrieve a lotto numbers that I
Problem I have a UDPlistener application that I need to write a unit test
I have WPF C# application that communicate with a PLC (i.e. write/read Omron PLC's

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.