Sign in to follow this  
Makaan

timeGetTime or QueryPerformanceCounter

Recommended Posts

Makaan    100
Hello, I need to design a timer to work with multiple threads. I have used timeGetTime before and worked well with no parallel programming. What i don't know is what works best for multiple threads and what are the implication of different CPU architecture (amd / intel) , will this affect the timers? For the start all i want is for each background thread to have a timer and the threads do not have affinity for the CPU. thanks.

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by Martin
Both should be fine I believe. RDTSC is the method you shouldn't use!
QPC() has some issues on older CPUs actually, and on some systems it's implemented as a RDTSC call - which means it'll break horribly on multiple processors / cores.

I'd suggest just sticking with timeGetTime(), unless you need timing more accurate than ~1ms.

Share this post


Link to post
Share on other sites
QueryPerformanceTimer() uses RTDSC on a widely available Windows version, and it uses it badly. On new hardware under Vista, there is no such issue, but you hardly have a way of knowing, unless you write "minimum requirement: Vista" on the package. In other words, the function isn't reliable.

timeGetTime() is ok, but has a much lower resolution. If that is acceptable, then timeGetTime() is the one you want to use.

RTDSC works fine on one CPU core, but otherwise shows random negative time step effects. I'm using RTDSC in a separate thread that binds to CPU0 and updates the tick counter at request when a semaphore is posted. That sounds terrible, but it's (surprisingly) quite fast, and for all I can tell, it works 100% reliably.

Share this post


Link to post
Share on other sites
popsoftheyear    2194
Quote:
Original post by gekko
Microsoft recommends QPC:

http://msdn.microsoft.com/en-us/library/bb173458(VS.85).aspx


That article suggests QPC because of flaws in RTDSC, but yet it was just noted that some versions of XP have QPC implemented using RTDSC...

I personally use timeGetTime. It too has its own problems (not counting the 1ms resolution "issue"), but of the limited choices at your disposal, it seems to be the least of evils.

Search around here for older threads on this topic, and you'll find an abundance of information.

Cheers
-Scott

[edit] I'd be really curious as to if anyone has any insight to potential problems with samoth's method.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this