How to get a thread's execution time

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: How to get a thread's execution time

 
0
  #11
Jul 6th, 2009
When you spawn the thread you pass a void user value!
Why not pass a boolean pointer! Loop while it is set and when false fall out of the thread loop. Don't forget your thread exit function for proper cleanup.
  1. void MyWorker( void *foo )
  2. {
  3. bool *pbSignal = (bool *)foo;
  4.  
  5. while (foo)
  6. {
  7.  
  8.  
  9. }
  10.  
  11. }

Or pass in a local index for that worker thread.

  1. void MyWorker( void *foo )
  2. {
  3. uint idx = (uint)foo;
  4.  
  5. while ( gbAppActive == true )
  6. {
  7.  
  8.  
  9. }
  10.  
  11. gThreadActive[ idx ] = false; // Tell root that this thread is shut down
  12.  
  13. }


In application root cleanup.
Loop for up until all gThreadActive[] become clear or the clock runs out, whichever comes first.

If you use semaphores, use a single gThreadActive parameter and merely clear the bit!
  1. LOCK();
  2. gThreadActive ^= 1 << idx;
  3. UNLOCK();
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 31
Reputation: rmlopes is an unknown quantity at this point 
Solved Threads: 0
rmlopes rmlopes is offline Offline
Light Poster

Re: How to get a thread's execution time

 
0
  #12
Jul 7th, 2009
When you spawn the thread you pass a void user value!
Why not pass a boolean pointer!
When you spawn the thread you pass a void pointer, which means you pass a pointer to something (or nothing). I am already using this to pass some arguments to the threads.
Wildgoose, I don't get what this last post has to offer to the discussion.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to get a thread's execution time

 
0
  #13
Jul 7th, 2009
I don't understand what's so difficult about thread timing. If you want the thread to quit after a specified amount of time, then just compare current time with original thread entry time and exit when that difference is greater than some pre-determined amount of time.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 31
Reputation: rmlopes is an unknown quantity at this point 
Solved Threads: 0
rmlopes rmlopes is offline Offline
Light Poster

Re: How to get a thread's execution time

 
0
  #14
Jul 7th, 2009
Originally Posted by Ancient Dragon View Post
I don't understand what's so difficult about thread timing. If you want the thread to quit after a specified amount of time, then just compare current time with original thread entry time and exit when that difference is greater than some pre-determined amount of time.
I don't understand what's so difficult about multi-threading for you. Threads yield execution to other threads and gain it back and yield again... etc. When they yeld they are not running anymore so any "raw" difference between starting time and current time is *not* what you want. Stop insisting please... I would flag your last post as a bad post...

NOTE: as mentioned in a previous post this issue can be solved in UNIX by using clock_gettime with the flag CLOCK_THREAD_CPUTIME_ID. I don't even need to save the start point because each thread's clock is set to 0 when it starts. I made the tests, 10 threads executing for 50 seconds in a core-duo processor, giving total time ~= 250 seconds, perfect for me!
I am still looking for a solution which can be applied cross-platform, or at least a similar solution for windows.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How to get a thread's execution time

 
0
  #15
Jul 7th, 2009
GetThreadTimes()

I have not used it and don't know if it will meet your needs. Did you overlook this thread?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 31
Reputation: rmlopes is an unknown quantity at this point 
Solved Threads: 0
rmlopes rmlopes is offline Offline
Light Poster

Re: How to get a thread's execution time

 
0
  #16
Jul 7th, 2009
Thanks, this looks like what I want for windows. As soon as I have tried it, I will post comments on it.
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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC