当我睡眠 1 秒时,我得到了通常的退出,但是当我注释掉sleep(1)
并编译并运行程序时,我得到了killed
为什么?我知道给睡眠不是正确的方法,我想知道如何处理我们必须调用 pthread kill 并确保线程正常退出的情况 |in a nutshell i want that atleast thread is created and running when pthread_kill is called
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
void *mythread(void *vargp)
{
printf("Printing from Thread \n");
// ...
...
printf("End of thread\n");
}
int main()
{
pthread_t thread_id;
printf("main start\n");
pthread_create(&thread_id, NULL, mythread, NULL);
sleep(1); // <----------- Here
pthread_kill(thread_id,SIGVTALRM);
}