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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:34:43+00:00 2026-05-27T11:34:43+00:00

GDB tells me that pthread_kill is causing a segmentation fault in my program. Basically

  • 0

GDB tells me that pthread_kill is causing a segmentation fault in my program. Basically I’m using pthread_kill to check if a thread is alive or not given its ID.

I’ve been searching the web and found that it might be that pthread_kill is causing segmentation fault when TID is invalid. Yes, I have been testing my program using “invalid”(contrived by me) TIDs of type int. Could that be the real cause?

  • 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-27T11:34:44+00:00Added an answer on May 27, 2026 at 11:34 am

    pthread_t is not a thread ID, or a numeric index. It is an opaque type. Making up values can result in a crash.

    On Linux NPTL, pthread_t is used as a pointer:

    int
    __pthread_kill (threadid, signo)
         pthread_t threadid;
         int signo;
    {
      struct pthread *pd = (struct pthread *) threadid;
    

    It should be fairly clear where things are going wrong already 🙂 Note that this pointerness is also an implementation detail – the older Linuxthreads implementation used numeric indices into a table, and there you could indeed make up TIDs and not expect things to crash.

    You need to be tracking thread life and death yourself. A pthread_t is valid until you call pthread_join on it successfully. If you want to test whether a valid pthread_t is alive, call pthread_tryjoin_np on it; if it returns EBUSY, the thread is alive. If the function succeeds, the pthread_t is no longer valid; you must not re-use it at this point – so you must make a note somewhere that that thread is dead now, and there’s no need to check it anymore!

    You could, of course, implement your own tracking system – create a table somewhere of liveness, a system for handing out TIDs, and passing them into newly created threads. Have each thread mark itself as dead prior to exiting (perhaps using pthread_cleanup_push so you handle thread cancellation and pthread_exit), and detach the thread so you don’t need to join it (using pthread_detach). Now you have explicit control of your thread-death reporting.

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

Sidebar

Related Questions

I am using g++ 4.1.2 and gdb 7.2 I am debugging code that uses
When using gdb and Vim, often I want to stop on a particular line.
Debugging with gdb, any c++ code that uses STL/boost is still a nightmare. Anyone
I'm outside gdb's target executable and I don't even have a stack that corresponds
I am debugging with GDB a crunching number C++ program. It takes 10 minutes
I have a program that depends on an external shared library, but after a
I have a C++ Android application that I'm trying to debug with ndk-gdb. The
Normally when you run a program through GDB you can press Ctrl+C to interrupt
I have a process x that I want to check for leaks with valgrind
I was writing a program that tell the user to input a random string,

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.