cancelling a thread inside a signal handler 
===

I have started a timer and set the interval as 5 secs and registered a signal handler for it. 
When SIGALRM is encountered  iam trying to terminate the thread inside the signal handler, bt not able to do that. Thread is not getting terminated , instead of this whole process is killed.  
The following is the code: 

     void signalHandler()
     16 {
     17         printf("Caught signal ...\n");
     18         printf("Now going to terminate thread..\n");
     19         pthread_kill(tid, SIGKILL);
     20 }
     21 
     22 void * thread_function()
     23 {
     24         int oldstate;
     25         char result[256] = {0};
     26         time_t startTime = time(NULL);
     27         time_t timerDuration = 5;
     28         time_t endTime = startTime + timerDuration;
     29 
     30         while(1) {
     31                 printf("Timer is runnuing as dameon..\n");
     32                 if(!strcmp(result, "CONNECTED")) {
     33                         resp = 1;
     34                         pthread_exit(&resp);
     35                 }
     36         }
     37 }
     38 
     39 int main()
     40 {
     41         int *ptr[2];
     42 
     43         signal(SIGALRM, signalHandler);
     44 
     45         timer.it_interval.tv_usec = 0;
     46         timer.it_interval. tv_usec = 0;
     47 
     48         timer.it_value.tv_sec = INTERVAL;
     49         timer.it_value.tv_usec = 0;
     50 
     51         setitimer(ITIMER_REAL, &timer, 0);
                pthread_create(&tid, NULL, thread_function, NULL);
     54         pthread_join(tid, (void**)&(ptr[0]));
     55         printf("test %d\n\n",*ptr[0]);
     56 
     57         while(1)
     58                 printf("1");
     59 }
                                                                                                                                                               9,0-1         50%
     Platform : Linux , gcc compiler 