Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda