LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-05-2011, 09:29 AM   #1
shankar.489
Member
 
Registered: Jan 2011
Posts: 53

Rep: Reputation: 0
Unhappy 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, 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
 
Old 07-05-2011, 06:31 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You may want to ask the Mods (via the Report button) to move this to the Programming forum.
 
Old 07-06-2011, 12:28 AM   #3
shankar.489
Member
 
Registered: Jan 2011
Posts: 53

Original Poster
Rep: Reputation: 0
Cool

Quote:
Originally Posted by shankar.489 View Post
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, 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
my problem has been solved now and now above program will work fine pleople can use it for exploration purpose..?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
do threads in the process share the signal handler? feiyinzilgd Linux - Software 5 08-23-2010 04:15 AM
do threads in the process share the signal handler? feiyinzilgd Programming 1 08-22-2010 09:03 AM
changing context thread of sw signal handler nesta Programming 5 06-01-2009 11:01 PM
user-define signal handler & coredump for signal 11(SIGSEGV) Alexlun Linux - Software 2 05-24-2009 06:37 AM
How to reinstall a signal handler after exec ( Strange behaviour in signal handling ) lali.p Programming 0 09-20-2008 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration