{"id":2526,"date":"2009-03-05T10:06:18","date_gmt":"2009-03-05T07:06:18","guid":{"rendered":"http:\/\/studentpmr.ru\/?p=2526"},"modified":"2009-03-05T10:06:18","modified_gmt":"2009-03-05T07:06:18","slug":"%d1%81%d0%b8%d0%bd%d1%85%d1%80%d0%be%d0%bd%d0%b8%d0%b7%d0%b0%d1%86%d0%b8%d1%8f-%d0%bf%d1%80%d0%b8-%d0%bf%d0%be%d0%bc%d0%be%d1%89%d0%b8-%d1%81%d0%be%d0%b1%d1%8b%d1%82%d0%b8%d0%b9","status":"publish","type":"post","link":"https:\/\/studentpmr.ru\/?p=2526","title":{"rendered":"\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439."},"content":{"rendered":"<p>\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u2013 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432: \u0441\u043e \u0441\u0431\u0440\u043e\u0441\u043e\u043c \u0432 \u0440\u0443\u0447\u043d\u0443\u044e , \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441 \u0430\u0432\u0442\u043e\u0441\u0431\u0440\u043e\u0441\u043e\u043c. \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f SetEvent. \u0414\u043b\u044f \u0441\u0431\u0440\u043e\u0441\u0430 \u0432 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 &#8212; ResetEvent.<br \/>\n\u0414\u043b\u044f \u043e\u0431\u0435\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0441\u043b\u0443\u0436\u0438\u0442 Handle \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<!--more--><br \/>\n\u0421\u043e\u0431\u044b\u0442\u0438\u044f \u0441 \u0430\u0432\u0442\u043e\u0441\u0431\u0440\u043e\u0441\u043e\u043c.<br \/>\n\u041f\u0440\u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043d\u044f\u0442\u044b\u043c \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443, \u0442\u043e\u0433\u0434\u0430 \u041e\u0421 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0431\u0440\u043e\u0441\u0438\u0442 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0435\u0439 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435, \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043a \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0437\u0430\u043d\u044f\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<br \/>\n\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f PulseEvent  &#8212; \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0436\u0434\u0443\u0449\u0435\u043c\u0443 \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0443 \u0438 \u0432\u043d\u043e\u0432\u044c \u0437\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435.<br \/>\n\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f : HANDLE CREATEEVENT (lp Security_Attributes, bool Manual_Reset, bool InitionState, LPSTR Name)<br \/>\n2.\u0435\u0441\u043b\u0438 TRUE, \u0442\u043e \u0441 \u0430\u0432\u0442\u043e\u0441\u0431\u0440\u043e\u0441\u043e\u043c.<br \/>\n3.\u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043d\u044f\u0442 \u0438\u043b\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u0435\u043d \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f.<br \/>\n4.\u0430\u043d\u0430\u043b\u043e\u0433 \u0438\u043c\u0435\u043d\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430.<br \/>\n\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<br \/>\n#define NUMTHREADS 4<br \/>\nHANDLE hGlobalWriteEvent;<br \/>\nVoid CreateEventAndThreads();<br \/>\n{ HANDLE hReaEvents[NUMTHREADS], hThread;<br \/>\nDWORD i, IDThread;<br \/>\nHGlobalWriteEvent = CreateEvent (NULL,TRUE,FALSE,NULL);<br \/>\n\/\/ \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0437\u0430\u043d\u044f\u0442\u043e<br \/>\nIf (hGlobalWriteEvent = NULL)<br \/>\nReturn;<br \/>\nFor (i = 1; i&lt;= NUMTHREADS;i++) \/\/\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043f\u043e\u0442\u043e\u043a, \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u0435\u043d\u0438\u0435\u043c<br \/>\n{hReadEvents[i-1] = CreateEvent(NULL,FALSE,TRUE,NULL);<br \/>\nhThread = CreateThread (NULL,0,THREADFUNCTION,&amp;hReadEvents[i-1],0,&amp;IDThread);<br \/>\n\/* THREADFUNCTION \u2013 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0438\u0437 \u043e\u0431\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, hReadEvents-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u201ci-1 \u043f\u043e\u0442\u043e\u043a\u0443 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u044c\u201d *\/<br \/>\n}<br \/>\n} \/\/\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044c<br \/>\nvoid WRITETOBUFFER( )<br \/>\n{<br \/>\nResetEvent(hGlobalWriteEvent); \/\/ \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c.<br \/>\nDWORD WR = WaitForMultipleObjects(NUMTHREADS, hReadEvents, TRUE, INFINITY);<br \/>\n\/\/ \u0436\u0434\u0430\u0442\u044c \u043f\u043e\u043a\u0430  \u0432\u0441\u0435 \u0447\u0438\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443<br \/>\nswitch(WR)<br \/>\n{case Wait_Object_0; \/\/ \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c<br \/>\nbreak;<br \/>\ndefault  \/\/  \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<br \/>\n}<br \/>\nSetEvent(hGlobalWriteEvent);  \/\/ \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430.<br \/>\nfor(i=0; i&lt;= NUMTHREADS; i++ )<br \/>\nSetEvent ( hReadEvents[ i ] )<br \/>\n}<br \/>\nvoid THREADFUNCTION (LPVOID Param)<br \/>\n{<br \/>\nHaldle hE[2];<br \/>\nhE [0] = (Handle *)Param;<br \/>\nhE [1] = hGlobalWriteEvent;<br \/>\npWaitForMultipleObjects(2,hE,TRUE,INFINITY);<br \/>\n\/\/  \u0435\u0441\u043b\u0438 \u0440\u0435\u0437-\u0442 \u044d\u0442\u043e\u0439 \u0444-\u0438\u0438 \u0440\u0430\u0432\u043d\u044f\u0435\u0442\u0441\u044f Wait_Object_0,\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430<br \/>\nSetEvent(hE[0]);<br \/>\n}<br \/>\n\u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u043c CloseHandle.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u2013 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0443\u0445 \u0442\u0438\u043f\u043e\u0432: \u0441\u043e \u0441\u0431\u0440\u043e\u0441\u043e\u043c \u0432 \u0440\u0443\u0447\u043d\u0443\u044e , \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441 \u0430\u0432\u0442\u043e\u0441\u0431\u0440\u043e\u0441\u043e\u043c. \u0414\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f SetEvent. \u0414\u043b\u044f \u0441\u0431\u0440\u043e\u0441\u0430 \u0432 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 &#8212; ResetEvent. \u0414\u043b\u044f \u043e\u0431\u0435\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0441\u043b\u0443\u0436\u0438\u0442 Handle \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"_links":{"self":[{"href":"https:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts\/2526"}],"collection":[{"href":"https:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2526"}],"version-history":[{"count":1,"href":"https:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts\/2526\/revisions"}],"predecessor-version":[{"id":2527,"href":"https:\/\/studentpmr.ru\/index.php?rest_route=\/wp\/v2\/posts\/2526\/revisions\/2527"}],"wp:attachment":[{"href":"https:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studentpmr.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}