{"id":772,"date":"2014-09-29T13:34:26","date_gmt":"2014-09-29T05:34:26","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=772"},"modified":"2014-09-29T13:35:22","modified_gmt":"2014-09-29T05:35:22","slug":"qworker%e6%9b%b4%e6%96%b0-%e5%9c%a8win32%e5%b9%b3%e5%8f%b0%e4%b8%8a%e6%9e%9a%e4%b8%be%e4%bd%9c%e4%b8%9a%e7%8a%b6%e6%80%81%e5%8a%a0%e4%b8%8a%e5%a0%86%e6%a0%88%e6%98%be%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=772","title":{"rendered":"QWorker\u66f4\u65b0-\u5728Win32\u5e73\u53f0\u4e0a\u679a\u4e3e\u4f5c\u4e1a\u72b6\u6001\u52a0\u4e0a\u5806\u6808\u663e\u793a"},"content":{"rendered":"<p>\u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u4e2d\uff0c\u6b7b\u9501\u662f\u4e00\u4e2a\u7ed5\u4e0d\u8fc7\u53bb\u7684\u8bdd\u9898\uff0c\u4e00\u65e6\u53d1\u751f\u6b7b\u9501\uff0c\u8981\u60f3\u77e5\u9053\u7a0b\u5e8f\u6b7b\u5728\u90a3\u513f\uff0c\u4e3a\u5565\u6b7b\u7684\uff0c\u662f\u4e00\u4e2a\u8270\u96be\u7684\u9009\u62e9\u3002QWorker\u4e3a\u7528\u6237\u65b0\u63d0\u4f9b\u7684EnumWorkerStatus\u51fd\u6570\uff0c\u53ef\u4ee5\u8f7b\u677e\u7684\u62a5\u544a\u6bcf\u4e2a\u5de5\u4f5c\u8005\u7684\u72b6\u6001\u3001\u6b63\u5728\u5904\u7406\u7684\u4f5c\u4e1a\u3001\u53ca\u5de5\u4f5c\u8005\u5904\u7406\u4f5c\u4e1a\u7684\u5806\u6808\u8c03\u7528\u60c5\u51b5\uff0c\u901a\u8fc7\u8ddf\u8e2a\u8fd9\u4e9b\u4fe1\u606f\uff0c\u5927\u5bb6\u53ef\u4ee5\u65b9\u4fbf\u7684\u6293\u53d6\u5230\u6bcf\u4e2a\u5de5\u4f5c\u8005\u5f53\u524d\u5728\u5e72\u4ec0\u4e48\uff0c\u4ece\u800c\u53ef\u4ee5\u786e\u5b9a\u51fa\u7cfb\u7edf\u4e2d\u7684\u4f5c\u4e1a\u662f\u90a3\u4e2a\u7ebf\u7a0b\u76f8\u4e92\u963b\u585e\u9020\u6210\u95ee\u9898\u53d1\u751f\u3002<\/p>\n<p>\u8981\u4f7f\u7528\u672c\u529f\u80fd\uff0c\u5fc5\u9700\u8ba9\u7f16\u8bd1\u5668\u751f\u6210Map\u6587\u4ef6\uff0c\u4ee5\u4fbf\u7a0b\u5e8f\u77e5\u9053\u6307\u5b9a\u7684\u5730\u5740\u5bf9\u5e94\u7684\u662f\u5565\u51fd\u6570\u53ca\u6e90\u7801\u4fe1\u606f\u3002\u5173\u4e8e\u8fd9\u65b9\u9762\u7684\u4fe1\u606f\uff0c\u8bf7\u53c2\u8003\u6587\u7ae0\uff1a<a href=\"https:\/\/blog.qdac.cc\/?p=704\" target=\"_blank\">Delphi\/C++ Builder Map\u6587\u4ef6\u683c\u5f0f\u89e3\u6790<\/a>\u3002<\/p>\n<p>\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u968f\u65f6\u8c03\u7528EnumWorkerStatus\u6765\u679a\u4e3e\u6bcf\u4e2a\u5de5\u4f5c\u8005\u7684\u72b6\u6001\u3002\u5f53\u6307\u5b9a\u7684\u5de5\u4f5c\u8005\u4e0d\u7a7a\u95f2\u65f6\uff0c\u5c31\u4f1a\u5217\u51fa\u76f8\u5e94\u7684\u5de5\u4f5c\u8005\u7684\u8c03\u7528\u5806\u6808\uff0c\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">procedure TForm1.Button32Click(Sender: TObject);\r\nvar\r\n  AStatus: TQWorkerStatus;\r\n  I: Integer;\r\n  S: String;\r\nbegin\r\nAStatus := Workers.EnumWorkerStatus;\r\nfor I := Low(AStatus) to High(AStatus) do\r\n  begin\r\n  S := S + '\u3010\u5de5\u4f5c\u8005 ' + IntToStr(I) + '(ID=' + IntToStr(AStatus[I].ThreadId) +\r\n    ')\u3011'#13#10 + ' \u5df2\u5904\u7406:' + IntToStr(AStatus[I].Processed) + ' \u72b6\u6001:';\r\n  if AStatus[I].IsIdle then\r\n    S := S + '\u7a7a\u95f2'#13#10#13#10\r\n  else\r\n    begin\r\n    S := S + '\u5fd9\u788c(\u4f5c\u4e1a:' + AStatus[I].ActiveJob + ')'#13#10;\r\n    if Length(AStatus[I].Stacks) &gt; 0 then\r\n      S := S + ' \u5806\u6808:'#13#10 + AStatus[I].Stacks + #13#10#13#10\r\n    else\r\n      S := S + #13#10;\r\n    end;\r\n  end;\r\nShowMessage(S);\r\nend;<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/EnumWorkerStatus.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-775\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/EnumWorkerStatus-300x278.jpg\" alt=\"EnumWorkerStatus\" width=\"300\" height=\"278\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/EnumWorkerStatus-300x278.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/EnumWorkerStatus.jpg 532w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u7ebf\u7a0b23\u5f53\u524d\u6b63\u5904\u4e8e\u5fd9\u788c\u4e2d\uff0c\u6267\u884c\u7684\u4f5c\u4e1a\u662fmain\u5355\u5143\u7684TForm1.DoLongTimeWork\u51fd\u6570\uff0c\u5176\u5b83\u7684\u5de5\u4f5c\u8005\u5904\u4e8e\u7a7a\u95f2\u72b6\u6001\u3002<\/p>\n<p>\u6211\u4eec\u518d\u7ed3\u5408EnumWaitChains\u51fd\u6570\uff0c\u5c31\u53ef\u4ee5\u5f88\u65b9\u4fbf\u8ddf\u8e2a\u51fa\u6b7b\u9501\u7684\u72b6\u6001\u3002<\/p>\n<p>\u3010\u6ce8\u610f\u3011<\/p>\n<p>EnumWaitChain\u662f\u8c03\u7528Windows\u7684API\uff0c\u6240\u4ee5\u53d7Windows\u7248\u672c\u9650\u5236\uff0c\u8fd0\u884c\u5728Windows Vista\u6216Windows Server 2008\u4ee5\u4e0a\u65f6\uff0c\u4f1a\u652f\u6301\u8be5\u529f\u80fd\u3002<\/p>\n<p>\u770b\u4e0b\u5728\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">...\r\nShowMessage(EnumWaitChains);\r\n...<\/pre>\n<p>\u8fd0\u884c\u6548\u679c\uff1a<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/WaitChains.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-776\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/WaitChains-300x217.jpg\" alt=\"WaitChains\" width=\"300\" height=\"217\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/WaitChains-300x217.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/WaitChains.jpg 399w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u770b\u4e0a\u9762\u7684\u7ed3\u679c\u4e2d\u7684\u7ebf\u7a0b7176\u7684\u72b6\u6001\uff1a<\/p>\n<pre class=\"lang:ini decode:true \"> \u7ebf\u7a0b 7176 &lt;\u8fd0\u884c\u4e2d&gt;\r\n CriticalSection &lt;\u7b49\u5f85\u4e2d&gt;\r\n \u7ebf\u7a0b 8988 &lt;\u8fd0\u884c\u4e2d&gt;<\/pre>\n<p>\u8fd9\u8bf4\u660e\u7ebf\u7a0b7176\u548c\u7ebf\u7a0b8988\u90fd\u5728\u4f7f\u7528\u540c\u4e00\u4e2a\u4e34\u754c\uff0c\u90a3\u4e48\u6211\u53ea\u9700\u8981\u518d\u7ed3\u5408\u5404\u4e2a\u7ebf\u7a0b\u7684\u5806\u6808\u4fe1\u606f\uff0c\u5c31\u53ef\u4ee5\u5b9a\u4f4d\u5230\u51fa\u9519\u7684\u884c\u3002<\/p>\n<pre class=\"lang:delphi decode:true\">ShowMessage(\r\n    '\u7ebf\u7a0b '+IntToStr(AThread1)+' \u5806\u6808'#13#10+StackByThreadId(AThread1)+\r\n    '\u7ebf\u7a0b \u2019+IntToStr(AThread2)+' \u5806\u6808'#13#10+StackByThreadId(AThread2)\r\n  );<\/pre>\n<p>\u770b\u5806\u6808\u8ddf\u8e2a\u6548\u679c\uff1a<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/debugstacks.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-777\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/debugstacks-300x295.jpg\" alt=\"debugstacks\" width=\"300\" height=\"295\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/debugstacks-300x295.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2014\/09\/debugstacks.jpg 569w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u597d\u5427\uff0c\u4ece\u4e0a\u9762\u770b\uff0c\u6211\u4eec\u9501\u51b2\u7a81\u5206\u522b\u4f4d\u4e8e\u7ebf\u7a0b8644\u7684\u7b2c77\u884c\u51fd\u6570TForm4.Button3Click\u548c\u7ebf\u7a0b7464\u7684\u7b2cSystem.SyncObjs.pas\u4e2d\u7684\u7b2c1023\u884c\u8bd5\u56fe\u8fdb\u5165\u4e34\u754c\uff0c\u8fd9\u6837\u4e00\u6e05\u4e8c\u695a\uff0c\u7136\u540e\u63a5\u4e0b\u6765\u7684\u4e8b\u60c5\u5c31\u662f\u53bb\u4fee\u6539\u4ee3\u7801\uff0c\u4fdd\u8bc1\u5b83\u4eec\u4e0d\u51b2\u7a81\u5c31\u597d\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u4e2d\uff0c\u6b7b\u9501\u662f\u4e00\u4e2a\u7ed5\u4e0d\u8fc7\u53bb\u7684\u8bdd\u9898 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,9,6],"tags":[20,83,82,84],"class_list":["post-772","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-qworker","tag-20","tag-83","tag-82","tag-84"],"views":4018,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=772"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/772\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}