{"id":340,"date":"2012-07-17T22:44:37","date_gmt":"2012-07-17T13:44:37","guid":{"rendered":"http:\/\/soundengine.jp\/wordpress\/tips\/?p=340"},"modified":"2014-02-06T23:42:36","modified_gmt":"2014-02-06T14:42:36","slug":"vc-criticalsection%e3%81%ae%e9%80%9f%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/soundengine.jp\/wordpress\/tips\/try\/340\/","title":{"rendered":"VC++ CriticalSection\u306e\u901f\u5ea6"},"content":{"rendered":"<p>\u6392\u4ed6\u7684\u5236\u5fa1\u3092\u884c\u3044\u305f\u3044\u6642\u306b\u4f7f\u3046\u306e\u304c\u3053\u306eCiriticalSection(\u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u30bb\u30af\u30b7\u30e7\u30f3)\u3002\u5177\u4f53\u7684\u306b\u3044\u3064\u4f7f\u3046\u306e\u304b\u3068\u3044\u3046\u3068\u3001\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u51e6\u7406\u306a\u3069\u3092\u3057\u3066\u3044\u308b\u6642\u306b\u3001\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3055\u308c\u308b\u3068\u307e\u305a\u3044\u90e8\u5206(\u30e1\u30e2\u30ea\u9818\u57df)\u304c\u3042\u308b\u5834\u5408\u306b\u4f7f\u3046\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4f8b\u3048\u3070\u30012\u3064\u30b9\u30ec\u30c3\u30c9\u304c\u3042\u3063\u305f\u6642\u3001\u4e00\u65b9\u306e\u30b9\u30ec\u30c3\u30c9\u3067\u914d\u5217\u306e\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3057\u3001\u3082\u3046\u7247\u65b9\u306e\u30b9\u30ec\u30c3\u30c9\u3067\u540c\u3058\u914d\u5217\u306e\u3042\u308b\u5834\u6240\u3092\u8aad\u307f\u8fbc\u3080\u5834\u5408\u3001\u914d\u5217\u30b5\u30a4\u30ba\u5909\u66f4\u4e2d\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u30a2\u30af\u30bb\u30b9\u9055\u53cd\u304c\u767a\u751f\u3057\u3001\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u843d\u3061\u308b\u3053\u3068\u304c\u3042\u308b\u3002<\/p>\n<p>Windows\u3067\u3053\u306eCriticalSection\u3092\u4f7f\u3046\u5834\u5408\u306f\u3001InitializeCriticalSection\u3001EnterCriticalSection\u3001LeaveCriticalSection\u3001DeleteCriticalSection\u3068\u3044\u3046\u95a2\u6570\u53ca\u3073CRITICAL_SECTION\u3068\u3044\u3046\u69cb\u9020\u4f53\u3092\u5229\u7528\u3059\u308b\u3002\u5177\u4f53\u7684\u4f7f\u3044\u65b9\u306a\u3069\u306f\u3001<a href=\"http:\/\/msdn.microsoft.com\/ja-jp\/library\/cc429223.aspx\" rel=\"nofollow\">MSDN<\/a>\u306a\u3069\u3067\u8abf\u3079\u3066\u3082\u3089\u3046\u3068\u3057\u3066\u3001\u4eca\u56de\u306f\u3053\u308c\u3092\u4f7f\u3063\u305f\u5834\u5408\u306e\u5b9f\u884c\u901f\u5ea6\u3092\u8abf\u3079\u3066\u307f\u305f\u3044\u3068\u601d\u3046\u3002<\/p>\n<h2 id=\"content_1_0\">\u901f\u5ea6  <a class=\"anchor_super\" id=\"yc66904c\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-05-30%2F3#yc66904c\" title=\"yc66904c\"> <\/a><\/h2>\n<p>\u901f\u5ea6\u306f\u3001\u5358\u7d14\u306afor\u30eb\u30fc\u30d7\u3068CriticalSection\u4ed8\u306e\u30eb\u30fc\u30d7\u3067\u8abf\u3079\u3066\u307f\u305f\u3002\u5177\u4f53\u7684\u306a\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a(\u30eb\u30fc\u30d7\u56de\u6570\u306f\u300148kHz\u30671\u6642\u9593\u5206\u3001\u6700\u9069\u5316\u306f\u7121\u52b9)<\/p>\n<pre>const int end = 60 * 60 * 48000;\r\n\r\nfor( int n = 0; n &lt; end; n++ )\r\n{\r\n}\r\n\r\nCRITICAL_SECTION CriticalSection;\r\n::InitializeCriticalSection( &amp;CriticalSection );\r\n\r\nfor( int n = 0; n &lt; end; n++ )\r\n{\r\n\t::EnterCriticalSection( &amp;CriticalSection );\r\n\t::LeaveCriticalSection( &amp;CriticalSection );\r\n}\r\n\r\n::DeleteCriticalSection( &amp;CriticalSection );<\/pre>\n<p>Intel Core 2 Duo\u306e\u30de\u30b7\u30f3\u3067\u6e2c\u5b9a\u3057\u3066\u307f\u305f\u304c\u3001\u4f55\u3082\u306a\u3044\u30eb\u30fc\u30d7\u304c\u30010.515106\u79d2\u306b\u5bfe\u3057\u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f7.089556\u79d2\u3068\u306a\u3063\u305f\u3002\u5358\u7d14\u306b\u8003\u3048\u305f\u5834\u5408\u30011\u30eb\u30fc\u30d7\u304c14\u500d\u9045\u304f\u306a\u3063\u3066\u3044\u308b(\u3053\u306e\u30b3\u30b9\u30c8\u3092\u3069\u3046\u8003\u3048\u308b\u304b\u3060\u304c\u3001\u4fe1\u53f7\u51e6\u7406\u306a\u30891\u30b5\u30f3\u30d7\u30eb\u3054\u3068\u306e\u51e6\u7406\u306a\u3069\u306b\u3053\u308c\u3092\u4f7f\u3046\u306b\u306f\u5411\u3044\u3066\u3044\u306a\u3044\u3060\u308d\u3046)\u3002<\/p>\n<p>\u307e\u305f\u3001\u3053\u308c\u3089\u306e\u95a2\u6570\u306f\u3001\u540c\u3058\u30b9\u30ec\u30c3\u30c9\u304b\u30892\u5ea6\u547c\u3093\u3067\u3082\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u3066\u304f\u308c\u308b\u3002\u3053\u308c\u306f\u3001\u30ed\u30c3\u30af\u30ab\u30a6\u30f3\u30c8\u304c\u3042\u308b\u305f\u3081\u3067\u3042\u308b\u3002<\/p>\n<pre>for( int n = 0; n &lt; end; n++ )\r\n{\r\n\t::EnterCriticalSection( &amp;CriticalSection );\r\n\t::EnterCriticalSection( &amp;CriticalSection );\r\n\t::LeaveCriticalSection( &amp;CriticalSection );\r\n\t::LeaveCriticalSection( &amp;CriticalSection );\r\n}<\/pre>\n<p>\u3053\u306e\u5834\u5408\u306e\u6e2c\u5b9a\u3057\u305f\u6642\u9593\u306f13.841430\u79d2\u3068\u306a\u308a\u3001\u3055\u3089\u306b\u500d\u5f31\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3053\u3068\u304b\u3089CriticalSection\u3092\u306a\u308b\u3079\u304f\u304b\u3076\u3089\u305b\u306a\u3044\u52aa\u529b\u306f\u82e5\u5e72\u5fc5\u8981\u3067\u3042\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6392\u4ed6\u7684\u5236\u5fa1\u3092\u884c\u3044\u305f\u3044\u6642\u306b\u4f7f\u3046\u306e\u304c\u3053\u306eCiriticalSection(\u30af\u30ea\u30c6\u30a3\u30ab &hellip; <a href=\"https:\/\/soundengine.jp\/wordpress\/tips\/try\/340\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-try"],"_links":{"self":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":5,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":3314,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/340\/revisions\/3314"}],"wp:attachment":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}