When I am giving a sleep of 1 second then i am getting a usual exit but when i comment out sleep(1)
and compile and run the program i get getting killed
why is that ?
I know giving sleep is not the right way ,i want to know how to deal a scenario where we have to call pthread kill and make sure thread exit normally | 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);
}