How to reuse pthreads in C

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 68
Reputation: rpjanaka is an unknown quantity at this point 
Solved Threads: 0
rpjanaka rpjanaka is offline Offline
Junior Poster in Training

How to reuse pthreads in C

 
0
  #1
Jan 14th, 2008
hi all,

i have a problem with pthread programming.

function_1(){
.
.
rc = pthread_create(&thread, &attr, my_function, (void *)&my_data);
.
rc = pthread_create(&thread, &attr, my_function, (void *)&my_data);
.
}

As the above “function_1” do, the “my_function” can be executed any number of time according to our need, but the problem is I have to create threads again and again. I think this is useless, because the input parameters are same at always (do not have to change).

So i want to do this(execute “my_function” regularly) with a one thread which is created at very first. Is this possible..?
please anyone can help me..
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,857
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: How to reuse pthreads in C

 
0
  #2
Jan 14th, 2008
Make the thread sleep for some time and execute my_function or else wait for some message to arrive in a message queue and then execute the function my_function.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 71
Reputation: Belrog is an unknown quantity at this point 
Solved Threads: 4
Belrog's Avatar
Belrog Belrog is offline Offline
Junior Poster in Training

Re: How to reuse pthreads in C

 
0
  #3
Jan 15th, 2008
I'd highly recommend the message queue method above the sleep method...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC