Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
pthread_cleanup_push handler not working for SIGINT (Ctrl C)

I have a code similar to :

myThread()
{
    pthread_cleanup_push(CleanupHandler , NULL)
    while (true)
    {
      /* some code here */
    }
    pthread_cleanup_pop(NULL)

 }

 static void CleanupHandler(void *arg)
 {
   printf("Cleaned\n");
 }

But if I terminate my application using ^C (SIGINT), the cleanup handler is not working. Is that expected ? What is the workaround to make the CleanupHandler work at ^C ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes, this is expected, as per man page, pthread_cleanup_push() executes in following 3 circumstances:

      1) When a thread is canceled
      2) thread terminates using pthread_exit()
      3) when pthread_cleanup_pop()

To workaround your problem you can register a signal handler for SIGINT, from that handler use pthread_exit() or pthread_cancel() to execute your handler. Hope this helps!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!