Archived

This topic is now archived and is closed to further replies.

GetTickCount and threads

This topic is 5811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just wanted to know whether GetTickCount measures how long the program has been running or how long the thread has been active. I''m using it to time how long my functions take (yes I know a high performance counter would be better), and I want to make sure extra time from other threads running in other programs would be counted. So if GetTickCount measures how long my main program thread is active, I shouldn''t have a problem. If it measures how long the program is running, then I might have to make a pure DOS program and boot my comp with DOS and run it. So which is it? No, HTML is not an OO language.

Share this post


Link to post
Share on other sites
It makes no difference. Just do this at thread startup.

  
//GLOBALS

int threadStartTime=GetTickCount();
int threadTimeRunning=0;
//Running code

While(inThread)
{
DoThreadStuff();
threadTimeRunning=(GetTickCount()-threadStartTime);
}


There, now you can tell how long the thread has been running no matter when GetTickCount starts. This same meathod can be applied to timing anything really.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
Yes, GetTickCount() returns the number of milliseconds since Windows was last booted. It has a granularity of 10ms, so if you need something with more resolution, then try QueryPerformanceCounter(), or the multimedia timers (timeBeginTime(), etc).

They will pretty much all return the same ''units'', meaning milliseconds since Windows was started.


-Brannon

Share this post


Link to post
Share on other sites