{"id":155521,"date":"2012-10-21T08:55:03","date_gmt":"2012-10-21T04:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=155521"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=155521","title":{"rendered":"<span class=\"post_title\">Active Object Pattern: \u041f\u043e\u0432\u044b\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447. \u041d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434!<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h4>\n<p>  \u0411\u044b\u0432\u0430\u044e\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u0431\u0438\u0442\u044b\u0435 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u00ab\u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0442\u044c\u00bb, \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u044d\u0442\u043e \u043f\u043e\u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043e\u0431\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432 \u0445\u0443\u0434\u0448\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0435 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043a\u0430\u0441\u0441\u044b. \u0412 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u0430\u0441\u0441\u0435 \u0441\u0442\u043e\u044f\u0442 \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0441 \u043f\u043e\u043b\u043d\u044b\u043c\u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u0430\u043c\u0438 \u043f\u043e\u043a\u0443\u043f\u043e\u043a, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0441\u0441\u044b \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u043e \u0432\u0441\u0435 \u043e\u043d\u0438 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0448\u043e\u043a\u043e\u043b\u0430\u0434\u043a\u043e\u0439. \u041a\u043e\u0433\u0434\u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u043a\u0430\u0441\u0441\u0430 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0442 \u0432\u0441\u0435\u0445 \u0441\u0432\u043e\u0438\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0442\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u0430\u0441\u0441\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u0430.<\/p>\n<p>  \u0414\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e, \u043d\u043e \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u00ab\u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435\u00bb \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0435\u0440\u0435\u0434 \u0442\u0443\u0440\u043d\u0438\u043a\u0435\u0442\u0430\u043c\u0438 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0432 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442. \u041a\u043e\u0433\u0434\u0430 \u0441\u0442\u0443\u0434\u0435\u043d\u0442 \u043f\u043e\u0434\u043d\u043e\u0441\u0438\u0442 \u043a\u0430\u0440\u0442\u0443 \u043a \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u0435\u043b\u044e, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 \u0435\u0433\u043e \u043a\u0430\u0440\u0442\u044b \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e, \u0430 \u0432\u043e\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u0441\u044f, \u043f\u0440\u0438\u0447\u0435\u043c \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442 \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438, \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e. \u0417\u0430\u0447\u0435\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435\u0445 \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u00ab\u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435\u00bb \u0434\u043b\u044f \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438?<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043f\u0440\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f ActiveObject.<\/p>\n<h4>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430<\/h4>\n<p>  \u0421\u0443\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b <b>\u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u043d \u0437\u0430\u043f\u0443\u0441\u043a \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442 \u043f\u043e\u0442\u043e\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f<\/b>. \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u00ab\u041a\u043e\u043c\u0430\u043d\u0434\u0430\u00bb (\u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f). \u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/bf1\/ac7\/3c2\/bf1ac73c280d92b85196d641f9d72c70.jpg\"\/><\/p>\n<p>  \u041a\u043b\u0438\u0435\u043d\u0442\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u044b-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 Command, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 execute(), \u0430 \u0442\u0430\u043a\u0436\u0435 ActiveObjectProxy, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439.<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441 GuardedQueue \u2013 \u044d\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u043e-\u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b push \u0438 pop. \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 Command.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 ActiveObject \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 <b>Sheduler<\/b> \u0438\u043b\u0438 \u00ab\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u00bb. \u0418\u043c\u0435\u043d\u043d\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041e\u0442\u043c\u0435\u0442\u0438\u043c \u0432\u0430\u0436\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:  <\/p>\n<ul>\n<li>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u00abthreadNumber\u00bb \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/li>\n<li>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f dispatch(), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u0432\u044b\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442 \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u00abqueue\u00bb \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 execute().<\/li>\n<\/ul>\n<p>  \u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e <b>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043f\u043e\u0442\u043e\u043a<\/b> (\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u043c, <b>\u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0438 \u00ab\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u044e\u0442\u00bb<\/b>, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u0430\u044f \u0432\u044b\u0448\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0439, \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432.  <\/p>\n<ul>\n<li>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u043a\u0430\u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 getResult() \u0438 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u00abCommand\u00bb. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d. \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0436\u0435 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u00abexecute()\u00bb \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430.<\/li>\n<li>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 ActiveObject. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0432\u044b\u0448\u0435\u043b \u0438\u0437 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0438 \u0441\u0430\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f. \u042d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0438\u0447\u044c, \u0441\u043e\u0437\u0434\u0430\u0432 \u043a\u043b\u0430\u0441\u0441-\u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a \u043e\u0442 Command \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c StopCommand. \u0414\u0430\u043b\u0435\u0435, \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0432 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 dispatch() \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 \u0432\u0435\u0440\u0445\u0443\u0448\u043a\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a\u043b\u0430\u0441\u0441\u0443 StopCommand. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 StopCommand \u0442\u0430\u043a\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0432\u043d\u043e \u0447\u0438\u0441\u043b\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0441\u0432\u043e\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435.<\/li>\n<\/ul>\n<h4>\u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c 1000 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 ConcretCommand \u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043b\u0430\u0441\u0441 Command \u0438 ConcretCommand \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"cpp\">class Command { protected: \tint sleep; \/\/ \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \tHANDLE semaphore; \tchar * name; public: \tCommand(char *uniqName, int _sleep) \t{\t\t \t\tname = new char[strlen(uniqName)]; \t\twchar_t *semName = new wchar_t[strlen(uniqName)]; \t\tfor (int i = 0; i &lt; strlen(uniqName); ++i) semName[i] = uniqName[i]; \t\tsemaphore = CreateSemaphore(NULL, 0, 1, semName); \t\tthis-&gt;sleep = _sleep; \t\tstrcpy(name, uniqName); \t}\t \tvoid getResult() \t{                 \/\/ \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \t\tWaitForSingleObject(semaphore, INFINITE);                 \/\/ \u0414\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \t\treturn; \t} \tvirtual void execute() = 0;\t \t~Command(void) \t{ \t} }; class ConcretCommand: \tpublic Command { public: \tConcretCommand(char *uniqName, int _sleep) : Command(uniqName, _sleep)  \t{ \t} \tvoid execute() \t{ \t\tSleep(sleep); \t\tReleaseSemaphore(semaphore, 1, 0); \t\t\/\/ \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0442\u0435\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u043b\u0438\u0448\u043d\u044f\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \t\t\/\/printf(&quot;My name: %s My sleep value: %d\\n&quot;, name, sleep);\t\t \t} \t~ConcretCommand(void)\t{} }; <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 1000 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 ConcretCommand \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434:  <\/p>\n<pre><code class=\"cpp\">for (int i = 0; i &lt; commandCount; ++i) { \tint sleep = rand() % 1000; \tif (i &lt; 4 * commandCount \/ 5) sleep \/= 10; \tcommand[i] = new ConcretCommand(intToStr(i + 1), sleep); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u00abcommandCount\u00bb \u0440\u0430\u0432\u043d\u0430 1000. <u>\u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e 20% \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0432 10 \u0440\u0430\u0437 \u0431\u043e\u043b\u044c\u0448\u0443\u044e, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438.<\/u> \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0439 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434.<br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438, \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u0430\u043c\u0435\u0440\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430.<br \/>  \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 \u0437\u0430\u043c\u0435\u0440\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:  <\/p>\n<pre><code class=\"cpp\">void execute(void *prm) { \tint thread = (int)prm; \tint count = commandCount \/ threadCount; \tif (commandCount % threadCount != 0) count++; \tint start = count * thread; \tfor (int i = start; i &lt; start + count && i &lt; commandCount; ++i) { \t\tcommand[i]-&gt;execute(); \t} \treturn; } \u2026 \u043a\u043e\u0434 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d \u2026 printf(&quot;\\nUse only multithreading:\\n&quot;); HANDLE threads[threadCount];\t time_t start = clock(), end; for (int i = 0; i &lt; threadCount; ++i) { threads[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)execute,     (LPVOID)i, NULL, NULL); } for (int i = 0; i &lt; commandCount; ++i) { \tcommand[i]-&gt;getResult(); } end = clock(); double firstTime = (double)(end - start) \/ CLK_TCK; printf(&quot;Time: %.3lf\\n\\n&quot;, firstTime); <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0438 \u0437\u0430\u043c\u0435\u0440\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">printf(&quot;Use active object pattern:\\n&quot;); ActiveObjectProxy * proxy = new ActiveObjectProxy(threadCount); start = clock(); for (int i = 0; i &lt; commandCount; ++i) { \tproxy-&gt;push(command[i]); }\t for (int i = 0; i &lt; commandCount; ++i) { \tcommand[i]-&gt;getResult(); } end = clock(); double secondTime = (double)(end - start) \/ CLK_TCK; printf(&quot;Time: %.2lf\\n&quot;, secondTime); <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435 IntelCore i5, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 Windows 7 Professional. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/912\/709\/a95\/912709a95b7c9f3fc77815ee39484cde.jpg\"\/><\/p>\n<p>  \u041f\u0430\u0442\u0442\u0435\u0440\u043d Active Object \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438, \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f, \u0432\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u0447\u0435\u0433\u043e \u043d\u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ActiveObject<\/h4>\n<p>  <\/p>\n<pre><code class=\"cpp\">class Proxy { private: \tSheduler * sheduler; public: \tProxy(int tCount) \t{ \t\tsheduler = new Sheduler(tCount); \t} \tvoid push(Command * someCommand) \t{ \t\tsheduler-&gt;push(someCommand); \t} \tvoid wait() \t{ \t\tsheduler-&gt;waitAll(); \t} \t~Proxy(void){} }; class Sheduler { private: \tGuardedQueue&lt;Command *&gt; *queue; \/\/ \u043f\u043e\u0442\u043e\u043a\u043e-\u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c! \tint tCount; \tHANDLE *threads;  \t\/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0442\u043e\u043a\u0430\u0445\t \tfriend void dispach(GuardedQueue&lt;Command *&gt; *);\t public:  \tSheduler(int _tCount) \t{ \t\ttCount = _tCount; \t\tthreads = new HANDLE[tCount]; \t\tqueue = new GuardedQueue&lt;Command *&gt;(); \t\tfor (int i = 0; i &lt; tCount; ++i) { \t\t\tthreads[i] = CreateThread(NULL, 0,  \t\t\t\t(LPTHREAD_START_ROUTINE)dispach, queue, NULL, NULL); \t\t} \t}  \tvoid push(Command *concretCommand) \t{ \t\tqueue-&gt;push(concretCommand); \t}\t  \tvoid waitAll() \t{ \t\tWaitForMultipleObjects(tCount, threads, true, INFINITE); \t}  \t~Sheduler(void){} };  void dispach(GuardedQueue&lt;Command *&gt; *queue) { \twhile (true) {\t\t \t\tCommand * someCommand = queue-&gt;pop(); \t\tsomeCommand-&gt;execute();\t\t \t} } template&lt;typename T&gt; class GuardedQueue { private: \tHANDLE semToPush, semToPop, control; \tqueue&lt;T&gt; my_queue;  \tbool condition; public: \tGuardedQueue(void) \t{ \t\tsemToPush = CreateSemaphore(NULL, 1, 1,  L&quot;semaphoreToPush_14.12.1989&quot;); semToPop = CreateSemaphore(NULL, 0, 1,  \t\t\tL&quot;semaphoreToPop_14.12.1989&quot;);\t\t\t \t\tcontrol = CreateSemaphore(NULL, 1, 1, L&quot;control_14.12.1989&quot;);\t \t} \tvoid push(const T& obj) \t{\t\t \t\tWaitForSingleObject(semToPush, INFINITE); \t\tWaitForSingleObject(control, INFINITE); \t\tmy_queue.push(obj); \t\tReleaseSemaphore(control, 1, 0); \t\tReleaseSemaphore(semToPop, 1, 0); \t\tReleaseSemaphore(semToPush, 1, 0); \t}  \tT pop() \t{ \t\tT obj = NULL;\t\t \t\twhile (obj == NULL) { \t\t\tWaitForSingleObject(semToPop, INFINITE); \t\t\tWaitForSingleObject(control, INFINITE); \t\t\tif (!my_queue.empty()) { \t\t\t\tobj = my_queue.front(); \t\t\t\tmy_queue.pop(); \t\t\t\tReleaseSemaphore(semToPop, 1, 0); \t\t\t} \t\t\tReleaseSemaphore(control, 1, 0); \t\t} \t\treturn obj; \t} }; <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/155521\/\"> http:\/\/habrahabr.ru\/post\/155521\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447. \u041d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434!  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-155521","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/155521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155521"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/155521\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}