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

  • Home
  • SEARCH
  • 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 1005241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:15:47+00:00 2026-05-16T08:15:47+00:00

When does one use pthread_cancel and not pthread_kill ?

  • 0

When does one use pthread_cancel and not pthread_kill?

  • 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-16T08:15:48+00:00Added an answer on May 16, 2026 at 8:15 am

    I would use neither of those two but that’s just personal preference.

    Of the two, pthread_cancel is the safest for terminating a thread since the thread is only supposed to be affected when it has set its cancelability state to true using pthread_setcancelstate().

    In other words, it shouldn’t disappear while holding resources in a way that might cause deadlock. The pthread_kill() call sends a signal to the specific thread, and this is a way to affect a thread asynchronously for reasons other than cancelling it.

    Most of my threads tends to be in loops doing work anyway and periodically checking flags to see if they should exit. That’s mostly because I was raised in a world when pthread_kill() was dangerous and pthread_cancel() didn’t exist.

    I subscribe to the theory that each thread should totally control its own resources, including its execution lifetime. I’ve always found that to be the best way to avoid deadlock. To that end, I simply use mutexes for communication between threads (I’ve rarely found a need for true asynchronous communication) and a flag variable for termination.

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

Sidebar

Related Questions

It does not seem that SendGrid has a free account that one could use
How does one use rm to delete a file named '--help'? When I try,
How does one use multiprocessing to tackle embarrassingly parallel problems ? Embarassingly parallel problems
how does one use code to do this: produce 15 random numbers [EDIT: from
How does one use boost::spirit with an input that consists of something other than
How does one use the CGRectIntegral function? I understand it's purpose. The documentation isn't
In .net, does a bool[] use one bit or one byte per array item?
How does one use the x264 C API to encode RBG images into H264
I have come across a website that appears to use Ajax but does not
How does one use QFileSystemModel in the context of a QCompleter ? It looks

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.