简体   繁体   中英

Why should I use my own TimerQueue when I can use the default one?

What advantages do I have from making my own TimerQueue by calling CreateTimerQueue and using it rather than just calling CreateTimerQueueTimer with a NULL value for TimerQueue and thus using the default one? I understand that if I use my own I can delete all the timers at once by deleting the queue. I can hardly imagine that this is the only advantage, what am I missing?

First thanks to HerrJoebob and Raymond Chen for their quality comments. I did not originally intend to answer my own question.

Reason 1: someone else deleting all timers in the default queue (thanks to HerrJoebob)

Reason 2: someone else putting a 'bajillion' (slang for very many) timers in the default queue and starving yours (thanks to Raymond Chen)

Reason 3: using the flag WT_EXECUTEINTIMERTHREAD saves a context switch when executing the callback, however if the callback takes a while it delays other timers. Using your own TimerQueue means you have your own timer thread so no one else can delay your timers and you can't inadvertently delay someone else's.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM