我有以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_t test_thread;
void *thread_test_run (void *v)
{
int i=1;
while(1)
{
printf("into thread %d\r\n",i);
i++;
sleep(1);
}
return NULL
}
int main()
{
pthread_create(&test_thread, NULL, &thread_test_run, NULL);
sleep (20);
pthread_cancel(test_thread);
sleep(100);
// In this period (before the finish of myprogram),
// I execute killall to kill myprogram
// I want to add a signal handle function to
// execute pthread_exit() before the program quit
}
我想通过在程序退出之前添加一个信号句柄函数来执行 pthread_exit() 来完成我的代码。
怎么做 ?