I am writting a multithread program using Qt (or any libraries). I will demonstrate about it:

All threads will be controled by the message mechanism. When a message send from a external program, my program will catch it & read information from the message and do the correlative task. Simplely, the external program only send 2 messages, the distance to send between 2 messages is 5 seconds. Each message need a correlative thread because in the received message have information about object will do this task & thread objects are different classes.

The first message: a threadA need 5 seconds to move objectA from X to Y. In duration, threadA will lock objectA to restrict other threads move it. After 5 seconds (after threadA started), a message received, a threadB will need 5 seconds to continuely move objectA from Y to Z.

If I set timer for threadA is 5 seconds but in fact, the system will need 5 seconds & 100 miliseconds ( 100 miliseconds only as a example, and it depend on CPU's speed) because when threadA started, it lost some miliseconds to do its tasks.

Like this, when threadB started, it can't control objectA because in this time, objectA is still controled by threadA.

I see that the multithread program depends on CPU's speed. How to solve this program so that threadA allways finish before threadB start.

Thanks.