简体   繁体   English

当我可以使用默认的TimerQueue时,为什么要使用自己的TimerQueue?

[英]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? 通过调用CreateTimerQueue并使用它而不是仅使用CreateTimerQueueTimerNULL值调用TimerQueue并因此使用默认值,我可以通过创建自己的TimerQueue有什么优势? 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. 首先感谢HerrJoebob和Raymond Chen的质量评论。 I did not originally intend to answer my own question. 我原本打算不回答我自己的问题。

Reason 1: someone else deleting all timers in the default queue (thanks to HerrJoebob) 原因1:其他人删除默认队列中的所有计时器(感谢HerrJoebob)

Reason 2: someone else putting a 'bajillion' (slang for very many) timers in the default queue and starving yours (thanks to Raymond Chen) 原因2:其他人将“bajillion”(俚语为很多)计时器放入默认队列并让你们挨饿(感谢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. 原因3:使用标志WT_EXECUTEINTIMERTHREAD在执行回调时保存上下文切换,但是如果回调需要一段时间,则会延迟其他定时器。 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. 使用你自己的TimerQueue意味着你有自己的计时器线程,所以没有其他人可以延迟你的计时器,你不能无意中推迟别人的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么时候应该使用自己的名称空间? - When I should use my own namespaces? 什么时候应该在C ++中使用自己的破坏函数? - When should I use destruction function of my own in C++? 是否应该使用std :: vector +我自己的大小变量? - Should I use std::vector + my own size variable or not? 创建自己的数据结构时,是否应该使用迭代器或索引来提供外部访问? - When creating my own data structure, should I use iterators or indices to provide access from the outside? 为什么我只能在我的代码中使用一个“while”循环? - Why can I use only one "while" loop in my code? 为什么以及何时应该使用 std::pair - Why and When should I use std::pair 我可以在Win32 GUI应用程序中使用默认控制台,还是应该创建一个新控制台? - Can I use the default console in a Win32 GUI application, or should I create a new one? 什么时候应该使用CUDA的内置warpSize而不是我自己的适当常数? - When should I use CUDA's built-in warpSize, as opposed to my own proper constant? 什么是“跨度”,我应该什么时候使用? - What is a "span" and when should I use one? 我可以在Windows中使用自己的消息循环吗? - Can I use my own message loop in windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM