I have a main thread that stays in the main function, i.e. I do not create it specifically, as in pthread_create, because it is optional. This thread opens the file, then creates other threads, waits for their completion (i.e. makes a connection), clears everything (pointers, semaphores, conditional variables, etc.).
Now I have to apply this code to block SIGINT:
sigset_t set; int sig; sigemptyset(&set); sigaddset(&set, SIGINT); pthread_sigmask(SIG_BLOCK, &set, NULL); while (1) { sigwait(&set, &sig); switch (sig) { case SIGINT: break; default: pthread_exit((void *)-1); } }
and he says that you should use the main () function to start the N + 1 threads and wait for them to complete. If the SIGINT signal enters the program, it must be processed by the main thread to close the program and its threads in a clean way.
My doubt is how do I put this code? Is it wrong to put on the background thread created in main ()? Since I already have a cicle with an exit flag that creates and joins all other threads, so I donβt understand if this code corresponds to the main function, where everything is executed / called to run the program. If I put it in a stream, with this code and a handler for cleaning, is it considered busy, waiting?
source share