Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

Let's suppose I have to set 2 different timers for a win32 / MFC Application.
Let's suppose that the first timer elapses after 60ms and the second after 30ms and that the callback function of the first timer takes 40ms to end the execution.

In this situation the function of the 30ms timer execute with a delay because the other function is still executing when the second timer triggers.

How is it possible to avoid this delay?

Have I to use multiple thread?

Thank You
Posted
Comments
Richard MacCutchan 5-Dec-13 8:48am    
Timers are neither exact nor guaranteed. You should not be using them to synchronise different pieces of code.
Optimistic76 5-Dec-13 9:06am    
I surely agree with you but my problem is to have the two function running at the same time.
do i have to use queue timers?
Richard MacCutchan 5-Dec-13 9:18am    
If you want them running at the same time then why do you need timers? If you need to synchronise the two at some point then use a mutex.
Optimistic76 5-Dec-13 10:35am    
I don't need synchronization between the two functions, but i need timer triggering.
i wrote "synch" in the question title because of the fact that the first function delays the second timer execution.I hope i explained the problem. Sorry i'm not english..

I need timers that execute in its own thread... Timer in QT are different?
Richard MacCutchan 5-Dec-13 11:39am    
You have not really explained what you are trying to do, so it is difficult to make any suggestions. I cannot see any reason why you would need timers to synchronise different threads. Don't worry about not being English, this site caters for people all over the world.

1 solution

You need multiple threads, running on multiple CPU cores (You know a single CPU cannot accomplish that).
 
Share this answer
 
Comments
Optimistic76 5-Dec-13 8:34am    
Thanks, I suspected that.

And if i start worker threads from the callback functions? In this situation the time to execute the functions would be only for the creation of the threads.Inside the threads there'll be the real execution.Is It a good scenario?
CPallini 5-Dec-13 8:36am    
Nope, in my opinion, due to thread creation overhead.
Albert Holguin 5-Dec-13 16:17pm    
Well, you could always use a thread pool for this type of scenario to avoid the overhead of creating new threads while executing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900