hi Folks,
iam a newbie to linux iam trying to implement timer specific to threads i have done below code, and blocked here can anybody help me to over come this
void* mythread(void* arg)
{
printf("%s","in mythread...\n");
while(1)
{
sleep(1);
printf("hai\n");
}
return NULL;
}
void timerthread(void *args)
{//
this is not being called
printf("timer thread called\n");
}
int main()
{
pthread_t tid;
timer_t timId;
int status;
struct itimerspec ts;
struct sigevent se;
ts.it_value.tv_sec=5;
ts.it_value.tv_nsec=0;
ts.it_interval.tv_sec=0;
ts.it_interval.tv_nsec=0;
//se.sigev_signo=1;
se.sigev_notify= SIGEV_THREAD; // (also tried //SIGEV_THREAD_ID)
pthread_create(&tid,NULL,mythread,NULL);
se.sigev_notify_function=timerthread;
(this is not being called dont know why)
se.sigev_notify_attributes=NULL;
//se.sigev_value.sival_ptr="hai";
se.sigev_notify_thread_id=tid;
if( timer_create(CLOCK_REALTIME,NULL,&timId))//also //tried CLOCK_THREAD_CPUTIME_ID
{
perror("timer");
return 0;
}
se.sigev_value.sival_ptr=&timId;
if(timer_settime(timId,NULL,&ts,NULL))
{
perror("settime");
}
perror("setime222");
pthread_join(tid,NULL);
printf("%s","thread finished\n");
return 0;
}
actually my requirement i need my program to call timerthread() api when ever timer expires(with void* as args to it) but here the timerthred is not being called at all after timer expiration SIGALRM is raising to process and my process is getting killed which i dont need.
can you people please let me know where iam wrong
, iam in urgent need
please input me in detail is possible, if tried searching it in google but didnt find solution
hope you reply soon
thanks in advance
thankyou,
shankar.
sorry i have typed subject wrongly