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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:47:45+00:00 2026-06-18T15:47:45+00:00

My application creates several threads with pthread_create() and then tries to verify their presence

  • 0

My application creates several threads with pthread_create() and then tries to verify their presence with pthread_kill(threadId, 0). Every once in a while the pthread_kill fails with “No such process”…

Could it be, I’m calling pthread_kill too early after pthread_create? I thought, the threadId returned by pthread_create() is valid right away, but it seems to not always be the case…

I do check the return value of pthread_create() itself — it is not failing… Here is the code-snippet:

    if (pthread_create(&title->thread, NULL,
        process_title, title)) {
        ERR("Could not spawn thread for `%s': %m",
            title->name);
        continue;
    }
    if (pthread_kill(title->thread, 0)) {
        ERR("Thread of %s could not be signaled.",
            title->name);
        continue;
    }

And once in a while I get the message about a thread, that could not be signaled…

  • 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-18T15:47:46+00:00Added an answer on June 18, 2026 at 3:47 pm

    That’s really an implementation issue. The thread may exist or it may still be in a state of initialisation where pthread_kill won’t be valid yet.

    If you really want to verify that the thread is up and running, put some form of inter-thread communication in the thread function itself, rather than relying on the underlying details.

    This could be as simple as an array which the main thread initialises to something and the thread function sets it to something else as its first action. Something like (pseudo-code obviously):

    array running[10]
    
    def threadFn(index):
        running[index] = stateBorn
        while running[index] != stateDying:
            weaveYourMagic()
        running[index] = stateDead
        exitThread()
    
    def main():
        for i = 1 to 10:
            running[i] = statePrenatal
            startThread (threadFn, i)
        for i = 1 to 10:
            while running[i] != stateBorn:
                sleepABit()
    
        // All threads are now running, do stuff until shutdown required.
    
        for i = 1 to 10:
            running[i] = stateDying
    
        for i = 1 to 10:
            while running[i] != stateDead:
                sleepABit()
    
        // All threads have now exited, though you could have
        // also used pthread_join for that final loop if you
        // had the thread IDs.
    

    From that code above, you actually use the running state to control both when the main thread knows all other threads are doing something, and to shutdown threads as necessary.

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

Sidebar

Related Questions

We have an application that creates several threads using the pthread library. As we
My application creates photo and then inserts it into stock camera's bucket of gallery.
I'm creating an console application which needs to run several threads in order to
I have Application that contains main Activity, Service and several Threads run on this
I am creating an application that uses several threads as a result I want
I am working on Android application that has several threads - one of them
I have a simple console application that runs calculations in several threads (10-20 of
I have a multi-threaded application that creates 48 threads that all need to access
I have a static class that creates several worker threads in its constructor. If
I'm trying to write a ThreadManager for my C# application. I create several threads:

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.