4/8/2024 0 Comments Pthread c return![]() ![]() Pthread_sigmask(SIG_SETMASK, &oldset, NULL) Restore the old signal mask only for this thread. Install the signal handler for SIGINT. Pthread_create(&thread1, NULL, thread, &(unsigned int)) Pthread_sigmask(SIG_BLOCK, &sigset, &oldset) ![]() This will avoid them catching SIGINT instead of this thread. The threads will inherit the signal mask. sleep() is a cancellation point in this example. ![]() Printf("Thread %u running.n", *(unsigned int*)argument) The error-checking has been omitted for clarity. In your case, it seems a good opportunity to use cancellation points. Refer to Kill Thread in Pthread Library for more details. Have the threads install a signal handler which provides a mechanism for termination (setting a flag and reacting to EINTR).īoth approaches has caveats. The thread will terminate when requested to cancel and it reaches a cancellation point, thus ending execution in a controlled fashion There are mainly two approaches for thread termination. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |