{"id":315895,"date":"2024-05-21T00:12:49","date_gmt":"2024-05-20T16:12:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/315895.html"},"modified":"2024-05-21T00:12:57","modified_gmt":"2024-05-20T16:12:57","slug":"%e5%9c%a8windows%e6%9c%89%e5%93%aa%e4%ba%9b%e7%b1%bb%e4%bc%bctimerfd%e7%9a%84%e9%ab%98%e7%b2%be%e5%ae%9a%e6%97%b6%e5%99%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/315895.html","title":{"rendered":"\u5728windows\u6709\u54ea\u4e9b\u7c7b\u4f3ctimerfd\u7684\u9ad8\u7cbe\u5b9a\u65f6\u5668"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27035909\/86076365-bd4d-48be-a74e-9367bdabc921.webp\" alt=\"\u5728windows\u6709\u54ea\u4e9b\u7c7b\u4f3ctimerfd\u7684\u9ad8\u7cbe\u5b9a\u65f6\u5668\" \/><\/p>\n<p><p>Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u4e0d\u76f4\u63a5\u63d0\u4f9b\u4e0eLinux\u4e0b\u7684timerfd\u5b8c\u5168\u5bf9\u5e94\u7684\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u529f\u80fd\u3002\u4f46\u662f\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5305\u62ecQueryPerformanceCounter\u3001SetTimer\u3001timeSetEvent\u548cCreateW<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tableTimer\u7b49\u3002\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u7528\u4e8e\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u9ad8\u7cbe\u5ea6\u8ba1\u65f6\u9700\u6c42\uff0c\u5e76\u4e14\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u80cc\u666f\u3002\u4f8b\u5982\uff0c<strong>QueryPerformanceCounter<\/strong>\u63d0\u4f9b\u4e86\u975e\u5e38\u9ad8\u7684\u5206\u8fa8\u7387\uff0c\u975e\u5e38\u9002\u5408\u8fdb\u884c\u6027\u80fd\u8ba1\u6570\u548c\u7cbe\u5bc6\u65f6\u95f4\u6d4b\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u79cd\u65b9\u6cd5\u7684\u5177\u4f53\u4f7f\u7528\u548c\u573a\u666f\u9002\u5e94\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001QUERYPERFORMANCECOUNTER<\/h3>\n<\/p>\n<p><p>QueryPerformanceCounter\u662f\u4e00\u79cd\u63d0\u4f9b\u9ad8\u7cbe\u5ea6\u8ba1\u65f6\u7684API\u3002\u5b83\u53ef\u4ee5\u7528\u6765\u8ba1\u7b97\u975e\u5e38\u7cbe\u786e\u7684\u65f6\u95f4\u95f4\u9694\uff0c\u7cbe\u5ea6\u53ef\u8fbe\u5fae\u79d2\u7ea7\u3002\u8fd9\u4e2a\u8ba1\u6570\u5668\u4e0d\u4f9d\u8d56\u4e8eCPU\u7684\u65f6\u949f\u9891\u7387\uff0c\u56e0\u6b64\u5373\u4f7fCPU\u5728\u53d8\u9891\u8fd0\u4f5c\u4e0b\uff0c\u5b83\u7684\u8ba1\u6570\u7ed3\u679c\u4ecd\u7136\u7a33\u5b9a\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528QueryPerformanceCounter\u65f6\u9996\u5148\u5e94\u8c03\u7528QueryPerformanceFrequency\uff0c\u4ee5\u83b7\u5f97\u8ba1\u6570\u5668\u7684\u9891\u7387<\/strong>\u3002\u7136\u540e\uff0c\u901a\u8fc7\u4e24\u6b21\u8c03\u7528QueryPerformanceCounter\u83b7\u53d6\u7684\u503c\u76f8\u51cf\uff0c\u518d\u9664\u4ee5\u9891\u7387\uff0c\u5373\u53ef\u8ba1\u7b97\u51fa\u4e24\u4e2a\u65f6\u95f4\u70b9\u4e4b\u95f4\u7684\u65f6\u95f4\u5dee\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001SETTIMER &amp; KILLTIMER<\/h3>\n<\/p>\n<p><p>SetTimer\u4e3a\u7528\u6237\u63d0\u4f9b\u5468\u671f\u6027\u7684\u65f6\u95f4\u6d88\u606f\uff0c\u5b83\u5e76\u4e0d\u63d0\u4f9b\u7edd\u5bf9\u7684\u5b9a\u65f6\uff0c\u800c\u662f\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u4e4b\u540e\uff0c\u5c06\u4e00\u4e2a\u6d88\u606f\u653e\u5165\u6d88\u606f\u961f\u5217\u4e2d\uff0c\u5f53\u8be5\u6d88\u606f\u5230\u8fbe\u5e94\u7528\u7a0b\u5e8f\u7684\u6d88\u606f\u5faa\u73af\u5e76\u88ab\u5904\u7406\u7684\u65f6\u5019\uff0c\u624d\u771f\u6b63\u610f\u5473\u7740\u201c\u65f6\u95f4\u5230\u201d\u3002<\/p>\n<\/p>\n<p><p>SetTimer\u7684\u7cbe\u5ea6\u4e00\u822c\u7531\u7cfb\u7edf\u65f6\u949f\u51b3\u5b9a\uff0c\u6700\u9ad8\u7cbe\u5ea6\u7ea6\u4e3a10-15\u6beb\u79d2\u3002\u5982\u679c\u9700\u8981\u53d6\u6d88\u5b9a\u65f6\u5668\uff0c\u53ef\u4ee5\u8c03\u7528KillTimer\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001TIMESETEVENT &amp; TIMKILLEVENT<\/h3>\n<\/p>\n<p><p>\u8be5\u65b9\u6cd5\u4f7f\u7528multimedia timer\uff0c\u901a\u8fc7\u8c03\u7528timeSetEvent\u51fd\u6570\u6765\u8bbe\u7f6e\u3002\u8fd9\u4e2a\u5b9a\u65f6\u5668\u53ef\u4ee5\u8bbe\u7f6e\u56de\u8c03\u51fd\u6570\uff0c\u5f53\u5b9a\u65f6\u5668\u8d85\u65f6\u65f6\uff0c\u8fd9\u4e2a\u56de\u8c03\u51fd\u6570\u5c06\u88ab\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><p>multimedia timer\u5b9a\u4e49\u5728Windows Multimedia API\u4e2d\uff0c\u53ef\u4ee5\u63d0\u4f9b\u9ad8\u4e8eSetTimer\u7684\u7cbe\u5ea6\uff0c\u4e00\u822c\u53ef\u4ee5\u8fbe\u52301\u6beb\u79d2\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528\u5b8c\u6bd5\u540e\u5e94\u8c03\u7528timeKillEvent\u6765\u7ec8\u6b62\u5b9a\u65f6\u5668\uff0c\u4ee5\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001CREATEWAITABLETIMER &amp; SETWAITABLETIMER<\/h3>\n<\/p>\n<p><p>CreateWaitableTimer\u548cSetWaitableTimer\u7ec4\u5408\u4f7f\u7528\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540c\u6b65\u5b9a\u65f6\u5668\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u53ef\u4ee5\u5728\u7279\u5b9a\u65f6\u95f4\u5524\u9192\u7ebf\u7a0b\u3002\u8fd9\u79cd\u5b9a\u65f6\u5668\u63d0\u4f9b\u4e86\u975e\u5e38\u9ad8\u7684\u7cbe\u5ea6\u3002\u5f53\u5b9a\u65f6\u5668\u5230\u671f\u65f6\uff0c\u7b49\u5f85\u8fd9\u4e2a\u5b9a\u65f6\u5668\u7684\u7ebf\u7a0b\u5c06\u88ab\u5524\u9192\u3002<\/p>\n<\/p>\n<p><p>\u8fd9\u4e2a\u5b9a\u65f6\u5668\u4f7f\u7528\u4e86Windows\u5185\u6838\u5bf9\u8c61\uff0c\u6240\u4ee5\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u5728\u5355\u4e2a\u8fdb\u7a0b\u4e2d\u4f7f\u7528\uff0c\u8fd8\u53ef\u4ee5\u5728\u591a\u4e2a\u8fdb\u7a0b\u95f4\u5171\u4eab\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u73b0\u7cbe\u786e\u7684\u8ba1\u65f6\u548c\u4efb\u52a1\u8c03\u5ea6\u65f6\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u80fd\u591f\u63d0\u4f9b\u4e0d\u540c\u7a0b\u5ea6\u7684\u652f\u6301\u3002\u5f00\u53d1\u8005\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u6700\u9002\u5408\u7684\u65b9\u6848\u5b9e\u73b0\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u9ad8\u6548\u7a33\u5b9a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. Windows\u4e2d\u6709\u6ca1\u6709\u4e0etimerfd\u7c7b\u4f3c\u7684\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\uff1f<\/strong><br \/>\nWindows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u6ca1\u6709\u7c7b\u4f3c\u4e8eLinux\u4e2d\u7684timerfd\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Windows API\u6765\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u7684\u529f\u80fd\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u5728Windows\u4e2d\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u7684\u529f\u80fd\uff1f<\/strong><br \/>\n\u5728Windows\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6765\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u7684\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528Win32 API\u4e2d\u7684<code>SetTimer<\/code>\u51fd\u6570\u6765\u521b\u5efa\u5b9a\u65f6\u5668\uff0c\u901a\u8fc7\u8bbe\u7f6e\u5b9a\u65f6\u5668\u7684\u56de\u8c03\u51fd\u6570\u548c\u65f6\u95f4\u95f4\u9694\u6765\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u3002<\/li>\n<li>\u4f7f\u7528Multimedia Timer API\uff08MMTimer\uff09\u6765\u5b9e\u73b0\u66f4\u7cbe\u786e\u7684\u5b9a\u65f6\u5668\uff0cMMTimer\u53ef\u4ee5\u63d0\u4f9b\u6beb\u79d2\u7ea7\u7684\u7cbe\u5ea6\u3002<\/li>\n<\/ul>\n<p><strong>3. \u9664\u4e86timerfd\uff0c\u6709\u6ca1\u6709\u5176\u4ed6\u53ef\u66ff\u4ee3\u7684\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u65b9\u6848\uff1f<\/strong><br \/>\n\u9664\u4e86\u4f7f\u7528timerfd\u4ee5\u5916\uff0c\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u8fd8\u6709\u5176\u4ed6\u66ff\u4ee3\u65b9\u6848\u6765\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6216\u6846\u67b6\uff0c\u5982Boost.Asio\u6216Reactor\u6a21\u5f0f\uff0c\u5b83\u4eec\u63d0\u4f9b\u4e86\u8de8\u5e73\u53f0\u7684\u9ad8\u6027\u80fd\u7f51\u7edc\u7f16\u7a0b\u6846\u67b6\uff0c\u5e76\u4e14\u652f\u6301\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u529f\u80fd\u3002<\/li>\n<li>\u4f7f\u7528C++11\u6807\u51c6\u5e93\u4e2d\u7684<code>std::chrono<\/code>\u5e93\u6765\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\uff0c\u8be5\u5e93\u63d0\u4f9b\u4e86\u53ef\u79fb\u690d\u7684\u8de8\u5e73\u53f0\u65f6\u95f4\u5ea6\u91cf\u5355\u4f4d\u548c\u8ba1\u65f6\u529f\u80fd\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u4e0d\u76f4\u63a5\u63d0\u4f9b\u4e0eLinux\u4e0b\u7684timerfd\u5b8c\u5168\u5bf9\u5e94\u7684\u9ad8\u7cbe\u5ea6\u5b9a\u65f6\u5668\u529f\u80fd\u3002\u4f46\u662f\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb [&hellip;]","protected":false},"author":3,"featured_media":315902,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/315895"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=315895"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/315895\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/315902"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=315895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=315895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=315895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}