LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   reg:CHANGING SIGNAL HANDLER TABLE FOR THREADS (https://www.linuxquestions.org/questions/linux-newbie-8/reg-changing-signal-handler-table-for-threads-890025/)

shankar.489 07-05-2011 09:29 AM

reg:CHANGING SIGNAL HANDLER TABLE FOR THREADS
 
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:scratch:, 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.:cry:

sorry i have typed subject wrongly

chrism01 07-05-2011 06:31 PM

You may want to ask the Mods (via the Report button) to move this to the Programming forum.

shankar.489 07-06-2011 12:28 AM

Quote:

Originally Posted by shankar.489 (Post 4405723)
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,&se,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:scratch:, 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.:cry:

sorry i have typed subject wrongly

my problem has been solved now and now above program will work fine pleople can use it for exploration purpose..?


All times are GMT -5. The time now is 05:42 PM.