I am trying to write the program, which will stop and continue thread instead of cancel it. I need to know, how can I achieve that?
I want to use pthread_kill() function with SIGSTOP and SIGCONT signals to thread.
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
void *threadfunc(){
while(1){
printf("i am thread \n");
sleep(1);
}
}
void main(){
pthread_t thread;
pthread_create(&thread, NULL, threadfunc, NULL);
sleep(2);
pthread_kill(thread, SIGSTOP);
printf("signal sent \n");
sleep(2);
printf("i am main thread \n");
}
My expectation: Program starts, 2 times "i am thread" printed, pthread_kill sent signal to stop the thread, user see "signal sent" and "i am main thread". Actual results: Programs starts, 2 times "i am thread" printed, pthread_kill sent stop signal and program terminate