Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda