> > And my question is just theoretical: is this approach good or such > sleep() implementation not so good and why? I.e. will such sleep() > release processor's time for another thread or not? >
Using sleep() will allow the processor to work on a different thread. The issue is that sleep() will most likely "over sleep" and make your code run slower. Also, under Windows, there is a 15ms penalty for blocking a thread (put to sleep) by calling sleep() or using a mutex to lock. That means if you want your thread to sleep for 5ms, it will sleep for at least 15ms. (This is from my measurements on Windows XP and Windows 7 about five years ago. It may be outdated.) Best practices are to not to lock a thread for optimal performance. If you need to block for synchronization purposes, it is best to use a condition variable (QWaitCondition). This makes blocking a thread event driven by using a different thread (the one you are waiting on) wake up the original thread only at the proper time. In this way, your thread will never "over sleep" but instead block for the minimum amount of time.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest