int s, sig;
sigset_t set;
pthread_t thread_ceva,thread_sync;
sigemptyset(&set);
sigaddset(&set, SIGCHLD);
s = pthread_sigmask(SIG_SETMASK, &set, NULL);
if (s != 0)
//handle_error_en(s, "pthread_sigmask");
//s = pthread_create(&thread_sync, NULL, &sync_thread, (void *)&set);
//if (s != 0)
//handle_error_en(s, "pthread_create");
s = pthread_create(&thread_ceva, NULL, &ceva_thread, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
//test();
while(1)
{
s = sigwait(&set, &sig);
if (s != 0)
handle_error_en(s, "sigwait");
printf("[main] Signal handling thread got signal %d\n", sig);
}
本文探讨了在C语言中如何使用pthread库进行线程创建,并详细解释了sigset_t类型的使用,包括信号集的初始化、添加信号以及如何在主线程中等待信号到来。通过示例代码展示了如何创建一个用于处理特定信号的线程。
210

被折叠的 条评论
为什么被折叠?



