{"id":1460,"date":"2016-02-17T19:50:00","date_gmt":"2016-02-17T11:50:00","guid":{"rendered":"http:\/\/blog.dynox.cn\/?p=1460"},"modified":"2023-08-12T08:48:13","modified_gmt":"2023-08-12T00:48:13","slug":"fastmutex%e7%9a%84%e9%99%b7%e9%98%b1","status":"publish","type":"post","link":"https:\/\/blog.dynox.cn\/?p=1460","title":{"rendered":"FastMutex\u7684\u9677\u9631"},"content":{"rendered":"<div class=\"gruber-markdown\"><p><font size=\"2\">\u76f8\u5bf9ERESOURCE\u6765\u8bf4\uff0cFastMutex\u7684\u4f7f\u7528\u6bd4\u8f83\u65b9\u4fbf\uff0c\u4e0d\u7528\u8003\u8651\u7981APC\u95ee\u9898\uff0c\u4e5f\u4e0d\u7528\u8003\u8651FastMutex\u7ed3\u6784\u4f53\u7684\u91ca\u653e\uff0c\u7528\u5b8c\u5373\u53ef\u4ee5\u4e09\u4e0d\u7ba1\u3002\u5bf9\u4e8e\u7ade\u4e89\u4e0d\u6fc0\u70c8\u4e14\u8bfb\u5199\u4e0d\u660e\u663e\u7684\u60c5\u51b5\u4e0b\uff0c\u7528FastMutex\u8fd8\u662f\u4e0d\u9519\u7684\u3002<\/font><\/p>  <p><font size=\"2\">\u4e0d\u8fc7\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u8981\u6ce8\u610f\u5176\u9690\u85cf\u7684\u9677\u9631\uff1a<\/font><\/p>  <p><font size=\"2\">1\uff0cExAcquireFastMutex \u4f1a\u63d0\u5347IRQL\u81f3APC_LEVEL\uff0c\u4e14\u4fdd\u5b58\u539f\u6765\u7684IRQL\u7528\u4ee5\u5728ExReleaseFastMutex\u65f6\u6062\u590d\u3002\u6240\u4ee5\u5728\u5d4c\u5957\u83b7\u53d6FastMutex\u65f6\u8981\u7279\u522b\u6ce8\u610f\u653e\u9501\u4e00\u5b9a\u8981\u4f9d\u52a0\u9501\u987a\u5e8f\u53cd\u5411\u64cd\u4f5c\uff0c\u4e0d\u7136\u4f1a\u5bfc\u81f4IRQL\u7d0a\u4e71\u3002\u4e3a\u6b64\u7cfb\u7edf\u7279\u522b\u63d0\u4f9b\u4e86Unsafe\u64cd\u4f5c\u51fd\u6570(ExAcquireFastMutexUnsafe\u53caExReleaseFastMutexUnsafe)\uff0c\u8fd9\u4e24\u4e2a\u51fd\u6570\u4e0d\u4f1a\u64cd\u4f5cIRQL\uff0c\u4f46\u4f7f\u7528\u4e0a\u5374\u6709\u524d\u63d0\u6761\u4ef6\u3002<\/font><\/p>  <p><font size=\"2\">2\uff0cFastMutex\u7684\u5b9e\u73b0\u662f\u901a\u8fc7\u539f\u5b50\u9501\u4e0eGate\u5bf9\u8c61\u6765\u5b9e\u73b0\u7684\uff0c\u5728\u6ca1\u6709\u7ade\u4e89\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u539f\u5b50\u9501\u53ef\u4ee5\u901f\u5b9e\u73b0\u52a0\u9501\u53ca\u89e3\u9501\uff0c\u6b64\u5916Gate\u5bf9\u8c61\u662f\u4e0d\u53ef\u91cd\u5165\u7684\uff0c\u4e0d\u50cfEvent\u7b49(Dispatch Object)\u53caERESOURCE\u7b49\u53ef\u91cd\u5165\u7684\u9501(\u540c\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u52a0\u9501\u591a\u6b21\u4e0d\u4f1a\u6b7b\u9501)\u3002<\/font><\/p>  <p><font size=\"2\">\u81f3\u4e8eFastMutex\u4e3a\u4ec0\u4e48\u8981\u63d0\u5347IRQL\u81f3APC_LEVEL\u7684\u539f\u56e0\uff0c\u548c\u6587\u4ef6\u7cfb\u7edf\u8c03\u7528FsRtlEnterFileSystem\u7981APC\u7684\u539f\u56e0\u662f\u4e00\u6837\u7684\uff0c\u76f4\u63a5\u76ee\u7684\u662f\u9632\u6b62\u5f53\u524d\u7ebf\u7a0b\u88ab\u6302\u8d77(Suspend)\u3002\u8bbe\u60f3\u5728\u6ca1\u6709\u7981\u6b62APC\u7684\u60c5\u51b5\u4e0b\u8c03\u7528ExAcquireFastMutexUnsafe\u52a0\u9501\u4e4b\u540e\u7ebf\u7a0b\u968f\u65f6\u53ef\u80fd\u88ab\u6302\u8d77\uff0c\u4e00\u65e6\u88ab\u6302\u8d77\u7684\u8bdd\u7cfb\u7edf\u4e2d\u8bd5\u56fe\u83b7\u53d6\u8be5\u9501\u7684\u5176\u5b83\u7ebf\u7a0b\u5219\u53ea\u80fd\u7b49\u5f85\uff0c\u4e0d\u7ba1\u6b64\u7ebf\u7a0b\u662f\u5426\u9ad8\u4f18\u5148\u7ea7\u6216\u5173\u952e\u7684\u7cfb\u7edf\u4efb\u52a1\u3002\u540c\u7406\u53ef\u4ee5\u7406\u89e3Event\uff0cERESOURCE\u7b49\u4e3a\u4ec0\u4e48\u4e5f\u9700\u8981\u7981\u6b62APC\u7684\u539f\u56e0\u3002<\/font><\/p>  <p><font size=\"2\">\u9664\u4e86FastMutex\u4e4b\u5916\uff0cWindows\u5185\u6838\u8fd8\u5b9e\u73b0\u4e86\u53e6\u5916\u4e24\u79cdMutex: <\/font><font size=\"2\">Regular Mutex\u53caGuarded Mutex\u3002\u4e0d\u8fc7\u4eceWindows 8\u5f00\u59cb\uff0cGuardedMutext\u548cFastMutex\u7684\u5b9e\u73b0\u662f\u4e00\u6837\u7684\uff0c\u4e8c\u8005\u5e76\u65e0\u5dee\u522b\u3002Regular Mutex\u901a\u8fc7KeInitializeMutex\u521d\u59cb\u5316\uff0c\u52a0\u9501\u53ca\u653e\u9501\u662f\u901a\u8fc7KeWaitForXXXObject\u53caKeReleaseMutex\u6765\u64cd\u4f5c\u7684\u3002\u6211\u4eec\u77e5\u9053 Event\u4e5f\u662f\u901a\u8fc7KeWaitForXXXObject\u6765\u52a0\u9501\u7684\uff0c\u4f46\u662fRegular Mutex\u7684\u52a0\u9501\u64cd\u4f5c\u5374\u4f1a\u7981\u6b62\u5f53\u524d\u7ebf\u7a0b\u7684Kernel APC\uff0cEvent\u5374\u4e0d\u4f1a\uff0c\u6240\u4ee5\u5728\u64cd\u4f5cEvent\u4e4b\u524d\u8981\u663e\u793a\u5730\u8fdb\u5165\u4e34\u754c\u533a\u6216\u7981\u6b62APC\u64cd\u4f5c\u4ee5\u9632\u6b62\u53ef\u80fd\u7684\u6b7b\u9501\u53d1\u751f\u3002<\/font><\/p>  <p><font size=\"2\">\u9700\u8981\u6ce8\u610f\u7684\u662f\u7981\u6b62Kernel APC\u5e76\u4e0d\u4f1a\u5f71\u54cdi\/o\u64cd\u4f5c\uff0c\u4f46\u662fFastMutex\u53caGauardedMutex\u4e0d\u6b62\u662f\u7981\u6b62Kernel APC\uff0c\u8fd8\u4f1a\u7981\u6b62Special APC\uff0c\u8fd9\u6837\u7684\u8bddi\/o\u64cd\u4f5c\u662f\u4e0d\u5141\u8bb8\u7684\uff0c\u56e0\u4e3ai\/o\u5b8c\u6210\u4f8b\u7a0b\u662f\u5728Special APC\u4e2d\u505a\u7684\u3002\u8fd9\u4e9b\u7ec6\u5fae\u5dee\u522b\u5728\u4f7f\u7528\u4e2d\u5fc5\u987b\u8003\u8651\u5230\u3002<\/font><\/p><\/div>","protected":false},"excerpt":{"rendered":"<p>\u76f8\u5bf9ERESOURCE\u6765\u8bf4\uff0cFastMutex\u7684\u4f7f\u7528\u6bd4\u8f83\u65b9\u4fbf\uff0c\u4e0d\u7528\u8003\u8651\u7981APC\u95ee\u9898\uff0c\u4e5f\u4e0d\u7528\u8003\u8651FastMute [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[9],"tags":[572,571,573,394,280],"views":1681,"_links":{"self":[{"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=\/wp\/v2\/posts\/1460"}],"collection":[{"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1460"}],"version-history":[{"count":3,"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=\/wp\/v2\/posts\/1460\/revisions"}],"predecessor-version":[{"id":1463,"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=\/wp\/v2\/posts\/1460\/revisions\/1463"}],"wp:attachment":[{"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.dynox.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}