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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:20:21+00:00 2026-05-22T16:20:21+00:00

My daemon initializes itself in four different threads before it starts doing its things.

  • 0

My daemon initializes itself in four different threads before it starts doing its things. Right now I use a counter which is incremented when a thread is started and decremented when it is finished. When the counter hits 0 I call the initialization finished callback.

Is this the preferred way to do it, or are there better ways? I’m using POSIX threads (pthread) and I just run a while cycle to wait for the counter to hit 0.

Edit: pthread_barrier_* functions are not available on my platform although they do seem to be the best choice.

Edit 2: Not all threads exit. Some initialize and then listen to events. Basically the thread needs to say, “I’m done initializing”.

  • 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-22T16:20:22+00:00Added an answer on May 22, 2026 at 4:20 pm

    Rather than spinning, use the pthread mutex/condvar primitives. I’d suggest a single mutex to protect both the count of threads outstanding, and the condvar.

    The main loop looks like this:

    acquire mutex
    count=N_THREADS;
    start your N threads
    while (1) {
      if (count==0) break;
      cond_wait(condvar);
    }
    release mutex
    

    And when each thread is ready it would do something like this:

    acquire mutex
    count--
    cond_signal(condvar)
    release mutex
    

    (EDIT: I have assumed that the threads are to keep going once they have done their initialisation stuff. If they are to finish, use pthread_join as others have said.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some daemon processes that crashes every now and then and I want
So I have a daemon running on a Linux system, and I want to
I have a Solaris daemon written in Java6. Clients can connect to it using
I am writing a daemon running on an embedded platform that needs to change
I have a python daemon running as a part of my web app/ How
We have a small daemon application written in C for a couple of various
I wrote a little daemon in Perl that calls up FFMpeg to encode a
I am writing a daemon that utilizes inotify to monitor file access and it
I have a daemon app written in C and is currently running with no
I need to create daemon that will monitor certain directory and will process every

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.