QTimer incorrect timing

I have two Qtimers. T1 starts at 100ms. T2 starts at 2ms.

I put some var to control their timing. Why they aren't in time? Sometimes T2 reaches 55, or 54, or 53, but never at the exact condition? I would need that at every T1 timeout, T2 had done 50 timeouts!


Can someone please suggest me other methods of synchronization?


You cannot rely on timers for thread synchronization, because CPU timing is never exact. Other applications run in the background of your operating system and tweak the timing, so you cannot rely on it.

You must use other methods of synchronization, such as monitors, semaphores etc.

Your timer will never give you the right interval because dependencies on your OS thread, process scheduler. So in order to calculate a valid elapsed time you should get the system time in your timer tick method and calculate the delta between current time and timer start time. For synchronization you need mutexes or semaphores in case of thread synchronization.

Need Your Help

Increase file size to at least N on windows without race condition

c windows filesize

I am looking for a way to increase the size of a file to at least N bytes in a way that does not suffer from race conditions.

Saving User Data to Database From Facebook API

php facebook api

I am requesting Facebook Users tagged_places with the FB API V-4.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.