Pthread_cancel do not work in the sun

#include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <string.h> char a[]="Hello"; void * thread_body(void * param) { while(1) printf("%s\n", param); } int main(int argc, char *argv[]) { pthread_t threadHello; int code; pthread_create(&threadHello, NULL, thread_body, a); pthread_cancel(threadHello); pthread_exit(0); } 

When I compile and run it under Solaris 10 (SunOS 5.10), it does not stop. But under Linux, it works as intended.

+1
source share
1 answer

On POSIX, printf (and all stdio) can be a cancellation point. This is not required. I suspect Solaris just doesn't want to do this. Have you tried another function like sleep here?

If you really need printf to cancel, you will probably need to implement your own printf function as a wrapper for dprintf , but this will not work so well if you depend on the stdio built-in lock function ..

+4
source

Source: https://habr.com/ru/post/1436419/


All Articles