{"id":32782,"date":"2019-10-31T21:48:54","date_gmt":"2019-10-31T18:48:54","guid":{"rendered":"https:\/\/prohoster.info\/blog\/sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net\/"},"modified":"2019-10-31T21:48:54","modified_gmt":"2019-10-31T18:48:54","slug":"sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net","status":"publish","type":"post","link":"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net","title":{"rendered":"Satte Philosophen oder wettbewerbsorientierte Programmierung in .NET","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><img decoding=\"async\" alt=\"\u0421\u044b\u0442\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 .NET\" src=\"\/wp-content\/uploads\/2019\/04\/0741d661ca25e048583d23043dbb2d22.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 .Net, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0431\u0435\u0434\u0430\u044e\u0449\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432. \u041f\u043b\u0430\u043d \u0442\u0430\u043a\u043e\u0439, \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0434\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445). \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f.<\/p>\n<p><\/p>\n<p>\u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u043c\u0435\u0442\u044c \u044d\u0442\u043e? \u0422\u0440\u0430\u043d\u0437\u0438\u0441\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0437\u0430\u043a\u043e\u043d \u041c\u0443\u0440\u0430 \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0441\u0432\u0435\u0442\u0430 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u043e\u0441\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435, \u0442\u0440\u0430\u043d\u0437\u0438\u0441\u0442\u043e\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u0441\u0442\u0435\u0442, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043a\u0446\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c. \u0412 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 &#171;\u043e\u0431\u044b\u0447\u043d\u043e\u0435&#187; \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u043e\u0434\u0438\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a, \u0443\u0436\u0435 \u043d\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041f\u0440\u0438\u0447\u0435\u043c, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044d\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u044f\u0445: \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u0430\u0448\u0438\u043d \u0432 \u0441\u0435\u0442\u0438 (\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b). \u0412 .NET \u0435\u0441\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h2 id=\"anchorproblemanchor-zadacha\"><noindex><a rel=\"nofollow\" name=\"problem\"><\/a><\/noindex> \u0417\u0430\u0434\u0430\u0447\u0430<\/h2>\n<p><\/p>\n<p>\u042d\u0434\u0441\u0433\u0435\u0440 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u0430 \u0437\u0430\u0434\u0430\u0432\u0430\u043b \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441\u0432\u043e\u0438\u043c \u0443\u0447\u0435\u043d\u0438\u043a\u0430\u043c \u0435\u0449\u0435 \u0432 1965. \u0423\u0441\u0442\u043e\u044f\u0432\u0448\u0430\u044f\u0441\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0442\u0430\u043a\u0430\u044f. \u0415\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 (\u043e\u0431\u044b\u0447\u043d\u043e \u043f\u044f\u0442\u044c) \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432 \u0438 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0432\u0438\u043b\u043e\u043a. \u041e\u043d\u0438 \u0441\u0438\u0434\u044f\u0442 \u0437\u0430 \u043a\u0440\u0443\u0433\u043b\u044b\u043c \u0441\u0442\u043e\u043b\u043e\u043c, \u0432\u0438\u043b\u043a\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u0424\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u043c\u043e\u0433\u0443\u0442 \u0435\u0441\u0442\u044c \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u0442\u0430\u0440\u0435\u043b\u043e\u043a \u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u043f\u0438\u0449\u0435\u0439, \u0434\u0443\u043c\u0430\u0442\u044c \u0438\u043b\u0438 \u0436\u0434\u0430\u0442\u044c. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0435\u0441\u0442\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0443, \u043d\u0443\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0434\u0432\u0435 \u0432\u0438\u043b\u043a\u0438 (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0434\u0435\u043b\u0438\u0442 \u0432\u0438\u043b\u043a\u0443 \u0441 \u043f\u0435\u0440\u0432\u044b\u043c). \u0412\u0437\u044f\u0442\u044c \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0438\u043b\u043a\u0443 \u2014 \u0434\u0432\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0412\u0441\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0435\u0437\u043c\u043e\u043b\u0432\u043d\u044b\u0435. \u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043e\u043d\u0438 \u0434\u0443\u043c\u0430\u043b\u0438 \u0438 \u0431\u044b\u043b\u0438 \u0441\u044b\u0442\u044b \u0441\u043f\u0443\u0441\u0442\u044f \u0434\u0430\u0436\u0435 54 \u0433\u043e\u0434\u0430.<\/p>\n<p><\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0447\u0435\u0440\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u0412\u0438\u043b\u043a\u0438 \u043b\u0435\u0436\u0430\u0442 \u043d\u0430 \u043e\u0431\u0449\u0435\u043c \u0441\u0442\u043e\u043b\u0435 \u0438 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0445 \u0431\u0435\u0440\u0443\u0442, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c, \u0438 \u043a\u043b\u0430\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. \u0417\u0434\u0435\u0441\u044c \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0438? \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u0432\u0438\u043b\u043a\u0438 \u043d\u0435\u0442? \u0438 \u0434\u0440. \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432.<\/p>\n<p><\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 <code>Task.Run<\/code> \u043c\u0435\u0442\u043e\u0434:<\/p>\n<p><\/p>\n<pre><code class=\"cs\">var cancelTokenSource = new CancellationTokenSource();\nAction&lt;int&gt; create = (i) =&gt; RunPhilosopher(i, cancelTokenSource.Token);\nfor (int i = 0; i &lt; philosophersAmount; i++) \n{\n    int icopy = i;\n    \/\/ \u041f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0443\u043b\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u041c\u0435\u0442\u043e\u0434 RunDeadlock \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u044c\u0441\u044f \n    \/\/ \u0441\u0440\u0430\u0437\u0443, \u0430 \u0436\u0434\u0435\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a.\n    philosophers[i] = Task.Run(() =&gt; create(icopy), cancelTokenSource.Token);\n}<\/code><\/pre>\n<p><\/p>\n<p>\u041f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0423 \u044d\u0442\u043e\u0433\u043e \u043f\u0443\u043b\u0430 \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0438 CLR \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u0442\u0438\u0445 \u0437\u0430\u0434\u0430\u0447. \u041e\u0434\u0438\u043d \u043f\u0443\u043b \u043d\u0430 \u0432\u0441\u0435 AppDomain&#8217;\u044b. \u042d\u0442\u043e\u0442 \u043f\u0443\u043b \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430, \u0442.\u043a. \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0438\u0445 \u043e\u0447\u0435\u0440\u0435\u0434\u044f\u043c\u0438 \u0438 \u043f\u0440. \u041c\u043e\u0436\u043d\u043e \u0438 \u0431\u0435\u0437 \u043f\u0443\u043b\u0430, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Thread<\/code>, \u044d\u0442\u043e \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0434\u043e\u043b\u0433\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u0434\u043b\u044f Foreground \u043f\u043e\u0442\u043e\u043a\u0430 \u0438 \u0434\u0440. <\/p>\n<p><\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, <code>System.Threading.Tasks.Task<\/code> \u043a\u043b\u0430\u0441\u0441 \u2014 \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 <code>Thread<\/code>, \u043d\u043e \u0441\u043e \u0432\u0441\u044f\u043a\u0438\u043c\u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430\u043c\u0438: \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0430\u0441\u043a \u043f\u043e\u0441\u043b\u0435 \u0431\u043b\u043e\u043a\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0430\u0441\u043a\u043e\u0432, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438\u0445 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0445 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u043c\u043d. \u0434\u0440. \u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 async\/await \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 (Task-based Asynchronous Pattern, \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440 \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f IO \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438). \u041e\u0431 \u044d\u0442\u043e\u043c \u0435\u0449\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c.<\/p>\n<p><\/p>\n<p><code>CancelationTokenSource<\/code> \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0433 \u0441\u0430\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043f\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0443 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430.<\/p>\n<p><\/p>\n<h2 id=\"problemy-s-sinhronizaciey\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/h2>\n<p><\/p>\n<h3 id=\"blokirovannye-filosofy\">\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b<\/h3>\n<p><\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u043c\u044b \u0443\u043c\u0435\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043e\u0431\u0435\u0434\u0430\u0442\u044c:<\/p>\n<p><\/p>\n<pre><code class=\"cs\">\/\/ \u041a\u0442\u043e \u043a\u0430\u043a\u0438\u0435 \u0432\u0438\u043b\u043a\u0438 \u0432\u0437\u044f\u043b. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443: 1 1 3 3 - 1\u0439 \u0438 3\u0439 \u0432\u0437\u044f\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u043f\u0430\u0440\u044b.\nprivate int[] forks = Enumerable.Repeat(0, philosophersAmount).ToArray();\n\n\/\/ \u0422\u043e \u0436\u0435, \u0447\u0442\u043e RunPhilosopher()\nprivate void RunDeadlock(int i, CancellationToken token) \n{\n    \/\/ \u0416\u0434\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0443, \u0432\u0437\u044f\u0442\u044c \u0435\u0451. \u042d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e: \n    \/\/ while(true) \n    \/\/     if forks[fork] == 0 \n    \/\/          forks[fork] = i+1\n    \/\/          break\n    \/\/     Thread.Sleep() \u0438\u043b\u0438 Yield() \u0438\u043b\u0438 SpinWait()\n    void TakeFork(int fork) =&gt;\n        SpinWait.SpinUntil(() =&gt; \n            Interlocked.CompareExchange(ref forks[fork], i+1, 0) == 0);\n\n    \/\/ \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441 Interlocked.Exchange:\n    void PutFork(int fork) =&gt; forks[fork] = 0;\n\n    while (true)\n    {\n        TakeFork(Left(i));\n        TakeFork(Right(i));\n        eatenFood[i] = (eatenFood[i] + 1) % (int.MaxValue - 1);\n        PutFork(Left(i));\n        PutFork(Right(i));\n        Think(i);\n\n        \/\/ \u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e-\u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443.\n        token.ThrowIfCancellationRequested();\n    }\n}<\/code><\/pre>\n<p><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u0437\u044f\u0442\u044c \u043b\u0435\u0432\u0443\u044e, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0430\u0432\u0443\u044e \u0432\u0438\u043b\u043a\u0438 \u0438 \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0442\u043e \u0435\u0434\u0438\u043c \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0438\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. \u0412\u0437\u044f\u0442\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0432\u0438\u043b\u043a\u0438 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e, \u0442.\u0435. \u0434\u0432\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u0437\u044f\u0442\u044c \u043e\u0434\u043d\u0443 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e (\u043d\u0435\u0432\u0435\u0440\u043d\u043e: \u043f\u0435\u0440\u0432\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0438\u043b\u043a\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u0442\u043e\u0436\u0435, \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u0435\u0440\u0435\u0442, \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0435\u0440\u0435\u0442). \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e <code>Interlocked.CompareExchange<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 (<code>TSL<\/code>, <code>XCHG<\/code>), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438. \u0410 SpinWait \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>while(true)<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 &#171;\u043c\u0430\u0433\u0438\u0435\u0439&#187; \u2014 \u043f\u043e\u0442\u043e\u043a \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 (<code>Thread.SpinWait<\/code>), \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443 (<code>Thread.Yeild<\/code>) \u0438\u043b\u0438 \u0437\u0430\u0441\u044b\u043f\u0430\u0435\u0442 (<code>Thread.Sleep<\/code>).<\/p>\n<p><\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442.\u043a. \u043f\u043e\u0442\u043e\u043a\u0438 \u0441\u043a\u043e\u0440\u043e (\u0443 \u043c\u0435\u043d\u044f \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0441\u0435\u043a\u0443\u043d\u0434\u044b) \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442\u0441\u044f: \u0432\u0441\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0435\u0440\u0443\u0442 \u0441\u0432\u043e\u044e \u043b\u0435\u0432\u0443\u044e \u0432\u0438\u043b\u043a\u0443, \u0430 \u043f\u0440\u0430\u0432\u043e\u0439 \u043d\u0435\u0442. \u041c\u0430\u0441\u0441\u0438\u0432 forks \u0442\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: 1 2 3 4 5. <\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"\u0421\u044b\u0442\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 .NET\" src=\"\/wp-content\/uploads\/2019\/04\/a359da497976a943e63d419997fed1a3.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>\u041d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435, \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (deadlock). \u0417\u0435\u043b\u0435\u043d\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u2014 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f, \u0441\u0435\u0440\u044b\u043c \u2014 \u043f\u043e\u0442\u043e\u043a \u0441\u043f\u0438\u0442. \u0420\u043e\u043c\u0431\u0438\u043a\u0430\u043c\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Task&#8217;\u043e\u0432.<\/p>\n<p><\/p>\n<h3 id=\"golod-filosofov\">\u0413\u043e\u043b\u043e\u0434 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432<\/h3>\n<p><\/p>\n<p>\u0425\u043e\u0442\u044f \u0447\u0442\u043e\u0431\u044b \u043c\u044b\u0441\u043b\u0438\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0435\u0434\u044b \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u043d\u043e \u0433\u043e\u043b\u043e\u0434 \u043a\u043e\u0433\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u044e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0433\u043e\u043b\u043e\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435. \u0413\u043e\u043b\u043e\u0434\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0442\u043e\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0431\u0435\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u0434\u0435\u0434\u043b\u043e\u043a, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0442\u043e\u043a \u043d\u0435 \u0441\u043f\u0438\u0442, \u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0449\u0435\u0442 \u043a\u0430\u043a \u0431\u044b \u043f\u043e\u0435\u0441\u0442\u044c, \u043d\u043e \u0435\u0434\u044b \u043d\u0435\u0442. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u0443\u044e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u043b\u043a\u0443 \u043d\u0430\u0437\u0430\u0434, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e.<\/p>\n<p><\/p>\n<pre><code class=\"cs\">\/\/ \u0422\u043e \u0436\u0435 \u0447\u0442\u043e \u0438 \u0432 RunDeadlock, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0434\u0435\u043c \u0432\u0438\u043b\u043a\u0443 \u043d\u0430\u0437\u0430\u0434 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043b\u043e\u0445\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432.\nprivate void RunStarvation(int i, CancellationToken token)\n{\n    while (true)\n    {\n        bool hasTwoForks = false;\n        var waitTime = TimeSpan.FromMilliseconds(50);\n        \/\/ \u041f\u043b\u043e\u0445\u043e\u0439 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0443\u0436\u0435 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u043b\u043a\u0443:\n        bool hasLeft = forks[Left(i)] == i + 1;\n        if (hasLeft || TakeFork(Left(i), i + 1, waitTime))\n        {\n            if (TakeFork(Right(i), i + 1, TimeSpan.Zero))\n                hasTwoForks = true;\n            else\n                PutFork(Left(i)); \/\/ \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u043b\u043e\u0445\u043e\u0439 \u0444\u0438\u043b\u043e\u0441\u043e\u0444 \u043e\u0442\u0434\u0430\u0435\u0442 \u0432\u0438\u043b\u043a\u0443 \u043d\u0430\u0437\u0430\u0434.\n        } \n        if (!hasTwoForks)\n        {\n            if (token.IsCancellationRequested) break;\n            continue;\n        }\n        eatenFood[i] = (eatenFood[i] + 1) % (int.MaxValue - 1);\n        bool goodPhilosopher = i % 2 == 0;\n        \/\/ \u0410 \u043f\u043b\u043e\u0445\u043e\u0439 \u0444\u0438\u043b\u043e\u0441\u043e\u0444 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u0432\u0438\u043b\u043a\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u043e:\n        if (goodPhilosopher)\n            PutFork(Left(i));\n        \/\/ \u0410 \u0435\u0441\u043b\u0438 \u0438 \u043f\u0440\u0430\u0432\u0443\u044e \u043d\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442, \u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u0431\u0435\u0437 \u0435\u0434\u044b.\n        PutFork(Right(i));\n\n        Think(i);\n\n        if (token.IsCancellationRequested)\n            break;\n    }\n}\n\n\/\/ \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0436\u0434\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.\nbool TakeFork(int fork, int philosopher, TimeSpan? waitTime = null)\n{\n    return SpinWait.SpinUntil(\n        () =&gt; Interlocked.CompareExchange(ref forks[fork], philosopher, 0) == 0,\n              waitTime ?? TimeSpan.FromMilliseconds(-1)\n    );\n}<\/code><\/pre>\n<p><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u0432\u0430\u0436\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0434\u0432\u0430 \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430 \u0437\u0430\u0431\u044b\u0432\u0430\u044e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u043b\u0435\u0432\u0443\u044e \u0432\u0438\u043b\u043a\u0443. \u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u0438 \u0435\u0434\u044f\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0435\u0434\u044b, \u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0433\u043e\u043b\u043e\u0434\u0430\u0442\u044c, \u0445\u043e\u0442\u044f \u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442. \u0417\u0434\u0435\u0441\u044c \u043e\u043d\u0438 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0433\u043e\u043b\u043e\u0434\u0430\u044e\u0442, \u0442.\u043a. \u043f\u043b\u043e\u0445\u0438\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u043a\u043b\u0430\u0434\u0443\u0442 \u0441\u0432\u043e\u0438 \u0432\u0438\u043b\u043a\u0438 \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0430\u0437\u0430\u0434. \u0423 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0435\u0434\u044f\u0442 \u0433\u0434\u0435-\u0442\u043e \u0432 5 \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u043b\u043e\u0445\u0438\u0435. \u0422\u0430\u043a \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0417\u0434\u0435\u0441\u044c \u0435\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0440\u0435\u0434\u043a\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0435\u0440\u0443\u0442 \u043b\u0435\u0432\u0443\u044e \u0432\u0438\u043b\u043a\u0443, \u043f\u0440\u0430\u0432\u043e\u0439 \u043d\u0435\u0442, \u043e\u043d\u0438 \u043a\u043b\u0430\u0434\u0443\u0442 \u043b\u0435\u0432\u0443\u044e, \u0436\u0434\u0443\u0442, \u043e\u043f\u044f\u0442\u044c \u0431\u0435\u0440\u0443\u0442 \u043b\u0435\u0432\u0443\u044e \u0438 \u0442.\u0434. \u042d\u0442\u0430 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0442\u043e\u0436\u0435 \u0433\u043e\u043b\u043e\u0434\u0430\u043d\u0438\u0435, \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0430\u044f \u043d\u0430 \u0432\u0437\u0430\u0438\u043c\u043d\u0443\u044e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443. \u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0435\u0435 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u041d\u0438\u0436\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0434\u043b\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0430 \u043f\u043b\u043e\u0445\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430 \u0437\u0430\u0431\u0440\u0430\u043b\u0438 \u043e\u0431\u0435 \u0432\u0438\u043b\u043a\u0438, \u0430 \u0434\u0432\u0430 \u0445\u043e\u0440\u043e\u0448\u0438\u0445 \u0433\u043e\u043b\u043e\u0434\u0430\u044e\u0442.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"\u0421\u044b\u0442\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 .NET\" src=\"\/wp-content\/uploads\/2019\/04\/4d34f623e6d43b40e2fab95775d21631.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0438 \u043f\u0440\u043e\u0441\u044b\u043f\u0430\u044e\u0442\u0441\u044f \u0438\u043d\u043e\u0433\u0434\u0430 \u0438 \u043f\u0440\u043e\u0431\u0443\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441. \u0414\u0432\u0430 \u044f\u0434\u0440\u0430 \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442 (\u0437\u0435\u043b\u0435\u043d\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u043a \u0432\u0432\u0435\u0440\u0445\u0443). <\/p>\n<p><\/p>\n<h3 id=\"smert-filosofa\">\u0421\u043c\u0435\u0440\u0442\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430<\/h3>\n<p><\/p>\n<p>\u041d\u0443 \u0438 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0440\u0432\u0430\u0442\u044c \u0441\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0431\u0435\u0434 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432 \u2014 \u044d\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u0443\u043c\u0440\u0451\u0442 \u0441 \u0432\u0438\u043b\u043a\u0430\u043c\u0438 \u0432 \u0440\u0443\u043a\u0430\u0445 (\u0438 \u0435\u0433\u043e \u0442\u0430\u043a \u0438 \u043f\u043e\u0445\u043e\u0440\u043e\u043d\u044f\u0442). \u0422\u043e\u0433\u0434\u0430 \u0441\u043e\u0441\u0435\u0434\u0438 \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0431\u0435\u0437 \u043e\u0431\u0435\u0434\u0430. \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u0441\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>NullReferenceException<\/code> \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0444\u0438\u043b\u043e\u0441\u043e\u0444 \u0431\u0435\u0440\u0435\u0442 \u0432\u0438\u043b\u043a\u0438. \u0418, \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0447\u0438\u043c, \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u043c \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u043d\u0435 \u043f\u043e\u0439\u043c\u0430\u0435\u0442 (\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e <code>AppDomain.CurrentDomain.UnhandledException<\/code> \u0438 \u0434\u0440.). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0432 \u0441\u0430\u043c\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0438 \u0441 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p><\/p>\n<h2 id=\"oficiant\">\u041e\u0444\u0438\u0446\u0438\u0430\u043d\u0442<\/h2>\n<p><\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u043a\u0430\u043a \u043d\u0430\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u0432\u0437\u0430\u0438\u043c\u043d\u044b\u043c\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438, \u0433\u043e\u043b\u043e\u0434\u0430\u043d\u0438\u0435\u043c \u0438 \u0441\u043c\u0435\u0440\u0442\u044f\u043c\u0438? \u0411\u0443\u0434\u0435\u043c \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430 \u0434\u043e \u0432\u0438\u043b\u043e\u043a, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 (mutual exclusion) \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u041a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0440\u044f\u0434\u043e\u043c \u0441 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430\u043c\u0438 \u0441\u0442\u043e\u0438\u0442 \u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0434\u043d\u043e\u043c\u0443 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0443 \u0432\u0437\u044f\u0442\u044c \u0432\u0438\u043b\u043a\u0438. \u041a\u0430\u043a \u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442\u0430 \u0438 \u043a\u0430\u043a \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0435\u0433\u043e, \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435. <\/p>\n<p><\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442\u0430 \u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0432\u0438\u043b\u043a\u0430\u043c. \u0422.\u0435. \u0442\u0435\u043f\u0435\u0440\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0435 \u0436\u0434\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0443 \u0440\u044f\u0434\u043e\u043c, \u0430 \u0436\u0434\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442\u0430. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e User Space, \u0432 \u043d\u0435\u043c \u043c\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a\u0438\u0445-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0438\u0437 \u044f\u0434\u0440\u0430 (\u043e \u043d\u0438\u0445 \u043d\u0438\u0436\u0435).<\/p>\n<p><\/p>\n<h3 id=\"resheniya-v-prostranstve-polzovatelya\">\u0420\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h3>\n<p><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u0436\u0435, \u0447\u0442\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u0434\u0435\u043b\u0430\u043b\u0438 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0432\u0438\u043b\u043a\u043e\u0439 \u0438 \u0434\u0432\u0443\u043c\u044f \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430\u043c\u0438, \u0431\u0443\u0434\u0435\u043c \u043a\u0440\u0443\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u0438 \u0436\u0434\u0430\u0442\u044c. \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438 \u043a\u0430\u043a \u0431\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0432\u0438\u043b\u043a\u0430, \u0442.\u0435. \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0442 \u0444\u0438\u043b\u043e\u0441\u043e\u0444, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b \u044d\u0442\u0443 &#171;\u0437\u043e\u043b\u043e\u0442\u0443\u044e \u0432\u0438\u043b\u043a\u0443&#187; \u0443 \u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c SpinLock.<\/p>\n<p><\/p>\n<pre><code class=\"cs\">private static SpinLock spinLock = new SpinLock();  \/\/ \u041d\u0430\u0448 \"\u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442\"\nprivate void RunSpinLock(int i, CancellationToken token)\n{\n    while (true)\n    {\n        \/\/ \u0412\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 busy waiting. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u043e try, \u0447\u0442\u043e\u0431\u044b\n        \/\/ \u0432\u044b\u0431\u0440\u0430\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c SpinLock.\n        bool hasLock = false;\n        spinLock.Enter(ref hasLock);\n        try\n        {\n            \/\/ \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a (mutual exclusion).\n            forks[Left(i)] = i + 1;  \/\/ \u0411\u0435\u0440\u0435\u043c \u0432\u0438\u043b\u043a\u0443 \u0441\u0440\u0430\u0437\u0443, \u0431\u0435\u0437 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f.\n            forks[Right(i)] = i + 1;\n            eatenFood[i] = (eatenFood[i] + 1) % (int.MaxValue - 1);\n            forks[Left(i)] = 0;\n            forks[Right(i)] = 0;\n        }\n        finally\n        {\n            if(hasLock) spinLock.Exit();  \/\/ \u0418\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u043e \u0441\u043c\u0435\u0440\u0442\u044c\u044e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430.\n        }\n\n        Think(i);\n\n        if (token.IsCancellationRequested)\n            break;\n    }\n}<\/code><\/pre>\n<p><\/p>\n<p><code>SpinLock<\/code> \u044d\u0442\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0449\u0438\u043a, \u0441, \u0433\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0442\u0435\u043c \u0436\u0435 <code>while(true) { if (!lock) break; }<\/code>, \u043d\u043e \u0441 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 &#171;\u043c\u0430\u0433\u0438\u0435\u0439&#187;, \u0447\u0435\u043c \u0432 <code>SpinWait<\/code> (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f). \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0443\u043c\u0435\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0441\u044b\u043f\u043b\u044f\u0442\u044c \u0438\u0445 \u0438 \u043c\u043d. \u0434\u0440. \u0412 \u043e\u0431\u0449\u0435\u043c, \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0451 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0432\u0441\u0451 \u0442\u043e\u0442 \u0436\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0433\u043e\u043b\u043e\u0434\u0430\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442\u043d\u0435\u0435 \u0434\u0440\u0443\u0433\u0438\u0445, \u043d\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043e\u043b\u043e\u0442\u043e\u0439 \u0432\u0438\u043b\u043a\u0438 (Priority Inversion problem). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0447\u0435\u043d\u044c \u043e\u0447\u0435\u043d\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0438 \u043f\u0440. \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"\u0421\u044b\u0442\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 .NET\" src=\"\/wp-content\/uploads\/2019\/04\/97f55c27e06fda0a00cc1f033f031291.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>\u0420\u0438\u0441\u0443\u043d\u043e\u043a \u0434\u043b\u044f <code>SpinLock<\/code>. \u041f\u043e\u0442\u043e\u043a\u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e &#171;\u0432\u043e\u044e\u044e\u0442&#187; \u0437\u0430 \u0437\u043e\u043b\u043e\u0442\u0443\u044e \u0432\u0438\u043b\u043a\u0443. \u0421\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0430\u043b\u044b \u2014 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c. \u042f\u0434\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e: \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u043e\u043b\u043e 2\/3 \u044d\u0442\u0438\u043c\u0438 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<p><\/p>\n<p>\u0414\u0440\u0443\u0433\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0434\u0435\u0441\u044c \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e <code>Interlocked.CompareExchange<\/code> \u0441 \u0442\u0435\u043c \u0436\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435\u043c, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 (\u0432 \u0433\u043e\u043b\u043e\u0434\u0430\u044e\u0449\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430\u0445), \u043d\u043e \u044d\u0442\u043e, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0435. <\/p>\n<p><\/p>\n<p>\u041f\u0440\u043e <code>Interlocked<\/code> \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e <code>CompareExchange<\/code>, \u043d\u043e \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0418 \u0437\u0430\u043f\u0438\u0441\u0438. \u0410 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0432\u0442\u043e\u0440 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0432\u043d\u0435\u0441\u0442\u0438 \u0441\u0432\u043e\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f (\u0447\u0442\u0435\u043d\u0438\u0435 1, \u0447\u0442\u0435\u043d\u0438\u0435 2, \u0437\u0430\u043f\u0438\u0441\u044c 2, \u0437\u0430\u043f\u0438\u0441\u044c 1 \u043f\u043b\u043e\u0445\u0430\u044f), \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (Interlocked Anything \u043f\u0430\u0442\u0442\u0435\u0440\u043d).<\/p>\n<p><\/p>\n<h3 id=\"resheniya-v-rezhime-yadra\">\u0420\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u044f\u0434\u0440\u0430<\/h3>\n<p><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u0440\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u0446\u0438\u043a\u043b\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u0444\u0438\u0446\u0438\u0430\u043d\u0442 \u0443\u0441\u044b\u043f\u0438\u0442 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430 \u0438 \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442 \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0434\u043e. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0436\u0438\u043c \u044f\u0434\u0440\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0412\u0441\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u043c \u0447\u0430\u0441\u0442\u043e \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0442\u0435, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>AutoResetEvent<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 53 \u0440\u0430\u0437\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 <code>SpinLock<\/code> [\u0420\u0438\u0445\u0442\u0435\u0440]. \u041d\u043e \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043f\u043e \u0432\u0441\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p><\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0437\u0434\u0435\u0441\u044c \u044d\u0442\u043e \u0441\u0435\u043c\u0430\u0444\u043e\u0440, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0414\u0435\u0439\u043a\u0441\u0442\u0440\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0432\u0435\u043a\u0430 \u043d\u0430\u0437\u0430\u0434. \u0421\u0435\u043c\u0430\u0444\u043e\u0440 \u044d\u0442\u043e, \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439, \u0438 \u0434\u0432\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043d\u0435\u043c, \u2014 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c. \u0415\u0441\u043b\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043d\u043e\u043b\u044c, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u041a\u043e\u0433\u0434\u0430 \u0447\u0438\u0441\u043b\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a\u0438\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0440\u0443\u0433\u0438\u043c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c, \u0442\u043e\u0433\u0434\u0430 \u043f\u043e\u0442\u043e\u043a\u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f, \u0430 \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u043e\u043f\u044f\u0442\u044c \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0435\u0437\u0434\u0430 \u0432 \u0443\u0437\u043a\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u043e\u043c. .NET \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438: <code>AutoResetEvent<\/code>, <code>ManualResetEvent<\/code>, <code>Mutex<\/code> \u0438 \u0441\u0430\u043c <code>Semaphore<\/code>. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>AutoResetEvent<\/code>, \u044d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439: \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 0 \u0438 1 (false, true). \u0415\u0435 \u043c\u0435\u0442\u043e\u0434 <code>WaitOne()<\/code> \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e 0, \u0430 \u0435\u0441\u043b\u0438 1, \u0442\u043e \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u0442 \u0434\u043e 0 \u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0433\u043e. \u0410 \u043c\u0435\u0442\u043e\u0434 <code>Set()<\/code> \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0434\u043e 1 \u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0435\u0433\u043e, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u044f\u0442\u044c \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u0442 \u0434\u043e 0. \u0414\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442, \u043a\u0430\u043a \u0442\u0443\u0440\u043d\u0438\u043a\u0435\u0442 \u0432 \u043c\u0435\u0442\u0440\u043e.<\/p>\n<p><\/p>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0440\u0430\u0437\u0443. \u0422.\u0435. \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u043e\u0433\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432, \u0430 \u043d\u0435 \u043e\u0434\u0438\u043d. \u041d\u043e \u043c\u044b \u043e\u043f\u044f\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u043e\u043b\u0443, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0433\u043e\u043d\u043e\u043a (race conditions), \u0432\u0437\u044f\u0442\u044c \u0432\u0438\u043b\u043a\u0438. <\/p>\n<p><\/p>\n<pre><code class=\"cs\">\/\/ \u0414\u043b\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430.\n\/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f: new AutoResetEvent(true) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e.\nprivate AutoResetEvent[] philosopherEvents;\n\n\/\/ \u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0432\u0438\u043b\u043a\u0430\u043c \/ \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u043e\u043b\u0443.\nprivate AutoResetEvent tableEvent = new AutoResetEvent(true);\n\n\/\/ \u0420\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430.\npublic void Run(int i, CancellationToken token)\n{\n    while (true)\n    {\n        TakeForks(i); \/\/ \u0416\u0434\u0435\u0442 \u0432\u0438\u043b\u043a\u0438.\n        \/\/ \u041e\u0431\u0435\u0434. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 \u0434\u043e\u043b\u044c\u0448\u0435.\n        eatenFood[i] = (eatenFood[i] + 1) % (int.MaxValue - 1);\n        PutForks(i); \/\/ \u041e\u0442\u0434\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0438 \u0438 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0435\u0434\u0435\u0439.\n        Think(i);\n        if (token.IsCancellationRequested) break;\n    }\n}\n\n\/\/ \u041e\u0436\u0438\u0434\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0438 \u0432 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0435.\nvoid TakeForks(int i)\n{\n    bool hasForks = false;\n    while (!hasForks) \/\/ \u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0435\u0449\u0435 \u0440\u0430\u0437 (\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0435 \u0437\u0434\u0435\u0441\u044c).\n    {\n        \/\/ \u0418\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u043e\u043b\u0443, \u0431\u0435\u0437 \u0433\u043e\u043d\u043e\u043a \u0437\u0430 \u0432\u0438\u043b\u043a\u0430\u043c\u0438.\n        tableEvent.WaitOne();\n        if (forks[Left(i)] == 0 &amp;&amp; forks[Right(i)] == 0)\n            forks[Left(i)] = forks[Right(i)] = i + 1;\n        hasForks = forks[Left(i)] == i + 1 &amp;&amp; forks[Right(i)] == i + 1;\n        if (hasForks)\n            \/\/ \u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444 \u043f\u043e\u0435\u0441\u0442, \u0432\u044b\u0439\u0434\u0435\u0442 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430. \u0415\u0441\u043b\u0438 Set \n            \/\/ \u0432\u044b\u0437\u0432\u0430\u043d \u0434\u0432\u0430\u0436\u0434\u044b, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 true.\n            philosopherEvents[i].Set();\n        \/\/ \u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0435\u0433\u043e. \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 tableEvent \u0432 false.\n        tableEvent.Set(); \n        \/\/ \u0415\u0441\u043b\u0438 \u0438\u043c\u0435\u0435\u0442 true, \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0430 \u0435\u0441\u043b\u0438 false, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c Set \u043e\u0442 \u0441\u043e\u0441\u0435\u0434\u0430.\n        philosopherEvents[i].WaitOne();\n    }\n}\n\n\/\/ \u041e\u0442\u0434\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0438 \u0438 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0435\u0434\u0435\u0439.\nvoid PutForks(int i)\n{\n    tableEvent.WaitOne(); \/\/ \u0411\u0435\u0437 \u0433\u043e\u043d\u043e\u043a \u0437\u0430 \u0432\u0438\u043b\u043a\u0430\u043c\u0438.\n    forks[Left(i)] = 0;\n    \/\/ \u041f\u0440\u043e\u0431\u0443\u0434\u0438\u0442\u044c \u043b\u0435\u0432\u043e\u0433\u043e, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u0441\u043e\u0441\u0435\u0434\u0430, \u043b\u0438\u0431\u043e AutoResetEvent \u0432 true.\n    philosopherEvents[LeftPhilosopher(i)].Set();\n    forks[Right(i)] = 0;\n    philosopherEvents[RightPhilosopher(i)].Set();\n    tableEvent.Set();\n}<\/code><\/pre>\n<p><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0443 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u0437\u044f\u0442\u044c \u0432\u0438\u043b\u043a\u0438, \u0442\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0442\u0430\u043a\u0438\u043c\u0438. \u041e\u043d \u0436\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0442\u043e\u043b\u0443. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0435\u0433\u043e \u043e\u043d \u043f\u0440\u043e\u0431\u0443\u0435\u0442 \u0432\u0437\u044f\u0442\u044c \u0432\u0438\u043b\u043a\u0438. \u041d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u041e\u043d \u043e\u0442\u0434\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u043e\u043b\u0443 (\u0432\u0437\u0430\u0438\u043c\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435). \u0418 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u0439 &#171;\u0442\u0443\u0440\u043d\u0438\u043a\u0435\u0442&#187; (<code>AutoResetEvent<\/code>) (\u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u043d\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044b). \u041f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043e\u043f\u044f\u0442\u044c \u0432 \u0446\u0438\u043a\u043b, \u0442.\u043a. \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u0432\u0438\u043b\u043e\u043a. \u041f\u0440\u043e\u0431\u0443\u0435\u0442 \u0432\u0437\u044f\u0442\u044c \u0438\u0445 \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0443 \u0441\u0432\u043e\u0435\u0433\u043e &#171;\u0442\u0443\u0440\u043d\u0438\u043a\u0435\u0442\u0430&#187;. \u041a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u0430\u0447\u043b\u0438\u0432\u044b\u0439 \u0441\u043e\u0441\u0435\u0434 \u0441\u043f\u0440\u0430\u0432\u0430 \u0438\u043b\u0438 \u0441\u043b\u0435\u0432\u0430, \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0432 \u0435\u0441\u0442\u044c, \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430, &#171;\u043e\u0442\u043a\u0440\u044b\u0432\u0430\u044f \u0435\u0433\u043e \u0442\u0443\u0440\u043d\u0438\u043a\u0435\u0442&#187;. \u041d\u0430\u0448 \u0444\u0438\u043b\u043e\u0441\u043e\u0444 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e (\u0438 \u043e\u043d \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u043d\u0438\u043c) \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437. \u041f\u0440\u043e\u0431\u0443\u0435\u0442 \u0432 \u0442\u0440\u0435\u0442\u0438\u0439 \u0440\u0430\u0437 \u0432\u0437\u044f\u0442\u044c \u0432\u0438\u043b\u043a\u0438. \u0423\u0434\u0430\u0447\u043d\u043e. \u0418 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u0439 \u0442\u0443\u0440\u043d\u0438\u043a\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0435\u0434\u0430\u0442\u044c.<\/p>\n<p><\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432 \u0442\u0430\u043a\u043e\u043c \u043a\u043e\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 (\u043e\u043d\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c), \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d \u0441\u043e\u0441\u0435\u0434 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 <code>AutoResetEvent<\/code> \u0434\u043b\u044f \u0432\u0441\u0435\u0445 (<code>Enumerable.Repeat<\/code>), \u0442\u043e\u0433\u0434\u0430 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0431\u0443\u0434\u0443\u0442 \u0436\u0434\u0430\u0442\u044c \u0443\u0436\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0442.\u043a. \u043f\u043e\u0438\u0441\u043a \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0442\u0430\u043a\u043e\u043c \u043a\u043e\u0434\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435. \u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u044d\u0442\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444 \u043d\u0435 \u043d\u0430\u0447\u043d\u0435\u0442 \u0433\u043e\u043b\u043e\u0434\u0430\u0442\u044c.<\/p>\n<p><\/p>\n<h3 id=\"gibridnye-resheniya\">\u0413\u0438\u0431\u0440\u0438\u0434\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p><\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0434\u0432\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u0441\u0442\u0430\u0435\u043c\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043a\u0440\u0443\u0442\u0438\u043c\u0441\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u0438, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0442\u043e\u043a \u0447\u0435\u0440\u0435\u0437 \u044f\u0434\u0440\u043e. \u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0445\u043e\u0440\u043e\u0448 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u0438\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a, \u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u043b\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445. \u0427\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 \u0446\u0438\u043a\u043b\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0433\u0434\u0430 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u0434\u043e\u043b\u0433\u043e\u0435. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u0442.\u043d. \u0433\u0438\u0431\u0440\u0438\u0434\u043d\u044b\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0442\u0435 \u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u0447\u0442\u043e \u0431\u044b\u043b\u0438 \u0434\u043b\u044f \u0440\u0435\u0436\u0438\u043c\u0430 \u044f\u0434\u0440\u0430, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0441 \u0446\u0438\u043a\u043b\u043e\u043c \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f: <code>SemaphorSlim<\/code>, <code>ManualResetEventSlim<\/code> \u0438 \u0434\u0440. \u0421\u0430\u043c\u0430\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0437\u0434\u0435\u0441\u044c \u044d\u0442\u043e <code>Monitor<\/code>, \u0442.\u043a. \u0432 C# \u0435\u0441\u0442\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0432\u0441\u0435\u043c <code>lock<\/code> \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441. <code>Monitor<\/code> \u044d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u0441\u0435\u043c\u0430\u0444\u043e\u0440 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c 1 (\u043c\u044e\u0442\u0435\u043a\u0441), \u043d\u043e \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0432 \u0446\u0438\u043a\u043b\u0435, \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438, Condition Variable \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 (\u043e \u043d\u0435\u043c \u043d\u0438\u0436\u0435) \u0438 \u0434\u0440. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u043d\u0438\u043c.<\/p>\n<p><\/p>\n<pre><code class=\"cs\">\/\/ \u0421\u043f\u0440\u044f\u0447\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0430 \u043e\u0442 \u0432\u0441\u0435\u0445, \u0447\u0442\u043e\u0431\u044b \u0431\u0435\u0437 \u0434\u0435\u0434\u043b\u043e\u043a\u043e\u0432.\nprivate readonly object _lock = new object();\n\/\/ \u0412\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430.\nprivate DateTime?[] _waitTimes = new DateTime?[philosophersAmount];\n\npublic void Run(int i, CancellationToken token)\n{\n    while (true)\n    {\n        TakeForks(i);\n        eatenFood[i] = (eatenFood[i] + 1) % (int.MaxValue - 1);\n        PutForks(i);\n        Think(i);\n        if (token.IsCancellationRequested) break;\n    }\n}\n\n\/\/ \u041d\u0430\u0448\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f Condition Variable \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430.\nbool CanIEat(int i)\n{\n    \/\/ \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u0438\u043b\u043a\u0438:\n    if (forks[Left(i)] != 0 &amp;&amp; forks[Right(i)] != 0)\n        return false;\n    var now = DateTime.Now;\n    \/\/ \u041c\u043e\u0436\u0435\u0442, \u0435\u0441\u043b\u0438 \u0441\u043e\u0441\u0435\u0434\u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u043e\u043b\u043e\u0434\u043d\u044b\u0435, \u0447\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0438\u0439.\n    foreach(var p in new int[] {LeftPhilosopher(i), RightPhilosopher(i)})\n        if (_waitTimes[p] != null &amp;&amp; now - _waitTimes[p] &gt; now - _waitTimes[i])\n            return false;\n    return true;\n}\n\nvoid TakeForks(int i)\n{\n    \/\/ \u0417\u0430\u0439\u0442\u0438 \u0432 \u041c\u043e\u043d\u0438\u0442\u043e\u0440. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435: lock(_lock) {..}.\n    \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u043d\u0435 try, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435.\n    bool lockTaken = false;\n    Monitor.Enter(_lock, ref lockTaken);\n    try\n    {\n        _waitTimes[i] = DateTime.Now;\n        \/\/ Condition Variable \u043f\u0430\u0442\u0442\u0435\u0440\u043d. \u041e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043b\u043e\u043a, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e \n        \/\/ \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435. \u0418 \u0436\u0434\u0435\u043c \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u0442 Pulse \/ PulseAll.\n        while (!CanIEat(i))\n            Monitor.Wait(_lock); \n        forks[Left(i)] = i + 1;\n        forks[Right(i)] = i + 1;\n        _waitTimes[i] = null;\n    }\n    finally\n    {\n        if (lockTaken) Monitor.Exit(_lock);\n    }\n}\n\nvoid PutForks(int i)\n{\n    \/\/ \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435: lock (_lock) {..}.\n    bool lockTaken = false;\n    Monitor.Enter(_lock, ref lockTaken);\n    try\n    {\n        forks[Left(i)] = 0;\n        forks[Right(i)] = 0;\n        \/\/ \u041e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u041f\u041e\u0421\u041b\u0415 \u0432\u044b\u0437\u043e\u0432\u0430 Monitor.Exit.\n        Monitor.PulseAll(_lock); \n    }\n    finally\n    {\n        if (lockTaken) Monitor.Exit(_lock);\n    }\n}<\/code><\/pre>\n<p><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u043f\u044f\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0432\u0435\u0441\u044c \u0441\u0442\u043e\u043b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0432\u0438\u043b\u043a\u0430\u043c, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0442\u043e\u043a\u0438, \u0430 \u043d\u0435 \u0441\u043e\u0441\u0435\u0434\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u0435\u0441\u0442\u044c. \u0422.\u0435. \u0441\u043d\u0430\u0447\u0430\u043b\u0430, \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0441\u0442 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0435\u0434\u0435\u0439, \u0430 \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e\u0442 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442, \u043d\u043e \u0445\u043e\u0447\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043e\u043f\u044f\u0442\u044c \u0435\u0441\u0442\u044c, \u043e\u043d \u0443\u0445\u043e\u0434\u0438\u0442 \u0432 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0438 \u0431\u0443\u0434\u0438\u0442 \u0441\u0432\u043e\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439, \u0442.\u043a. \u0435\u0433\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043c\u0435\u043d\u044c\u0448\u0435. <\/p>\n<p><\/p>\n<p>\u0422\u0430\u043a \u043c\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u0434\u0435\u0434\u043b\u043e\u043a\u043e\u0432 \u0438 \u0433\u043e\u043b\u043e\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0446\u0438\u043a\u043b \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0434\u043e\u043b\u0433\u043e\u0433\u043e. \u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u0435\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0435\u0441\u043b\u0438 \u0431\u044b \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0441\u0435\u0434\u0430, \u043a\u0430\u043a \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0441 <code>AutoResetEvent<\/code>, \u043d\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0442.\u043a. \u043f\u043e\u0442\u043e\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430. <\/p>\n<p><\/p>\n<p>\u0423 <code>lock<\/code> \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0435 \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u044b. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Monitor<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e [\u0420\u0438\u0445\u0442\u0435\u0440] [\u042d\u0440\u0438\u043a \u041b\u0438\u043f\u043f\u0435\u0440\u0442]. \u041e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>lock<\/code> \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 <code>Monitor<\/code>, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0438 \u0442\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0447\u0430\u0449\u0435 \u043b\u0443\u0447\u0448\u0435 \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0434\u0435\u0434\u043b\u043e\u043a \u0438\u043b\u0438 \u043a\u0430\u043a-\u0442\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u044e\u0440\u043f\u0440\u0438\u0437 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e Monitor \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u043b\u043e\u043a\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 (<code>SyncBlock<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d \u043d\u0435\u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0435\u0434\u043b\u043e\u043a (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u043e\u043a \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443). \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e.<\/p>\n<p><\/p>\n<p>Condition Variable \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0430\u0442\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0412 .NET \u043e\u043d \u043d\u0435\u043f\u043e\u043b\u043d\u044b\u0439, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0442.\u043a. \u043f\u043e \u0438\u0434\u0435\u0435 \u0442\u0430\u043c \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 (\u043a\u0430\u043a \u0432 Posix Threads), \u0430 \u043d\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043b\u043e\u043a\u0435. \u0422\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432. \u041d\u043e \u0438 \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u0434.<\/p>\n<p><\/p>\n<h3 id=\"mnogo-filosofov-ili-async--await\">\u041c\u043d\u043e\u0433\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432 \u0438\u043b\u0438 <code>async<\/code> \/ <code>await<\/code><\/h3>\n<p><\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u043c\u0435\u0435\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438. \u041d\u043e, \u0430 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432? 100? 10000? \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e 100000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440. \u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c, \u0442.\u043a. \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u0411\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u044f\u0434\u0435\u0440 (\u0443 \u043c\u0435\u043d\u044f 4). \u0410 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u041e\u0434\u043d\u043e \u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b async \/ await \u043f\u0430\u0442\u0442\u0435\u0440\u043d. \u0418\u0434\u0435\u044f \u0435\u0433\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0442\u043e\u043a, \u0435\u0441\u043b\u0438 \u0434\u043b\u044f \u0435\u0451 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c. \u0410 \u043a\u043e\u0433\u0434\u0430, \u043e\u043d\u0430 \u044d\u0442\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043e\u043d\u0430 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 (\u043d\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435!). \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0436\u0434\u0430\u0442\u044c \u0432\u0438\u043b\u043a\u0438. <\/p>\n<p><\/p>\n<p><code>SemaphoreSlim<\/code> \u0438\u043c\u0435\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e <code>WaitAsync()<\/code> \u043c\u0435\u0442\u043e\u0434. \u0412\u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430. <\/p>\n<p><\/p>\n<pre><code class=\"cs\">\/\/ \u0417\u0430\u043f\u0443\u0441\u043a \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0440\u0430\u043d\u044c\u0448\u0435. \u0413\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435:\nTask.Run(() =&gt; Run(i, cancelTokenSource.Token));\n\n\/\/ \u0417\u0430\u043f\u0443\u0441\u043a \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0430.\n\/\/ \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e async -- \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0442 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439.\npublic async Task Run(int i, CancellationToken token)\n{\n    while (true)\n    {\n        \/\/ await -- \u0431\u0443\u0434\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f.\n        await TakeForks(i);\n        \/\/ \u041f\u043e\u0441\u043b\u0435 await, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435.\n        eatenFood[i] = (eatenFood[i] + 1) % (int.MaxValue - 1);\n        \/\/ \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f.\n        await PutForks(i);\n\n        Think(i);\n\n        if (token.IsCancellationRequested) break;\n    }\n}\n\nasync Task TakeForks(int i)\n{\n    bool hasForks = false;\n    while (!hasForks)\n    {\n        \/\/ \u0412\u0437\u0430\u0438\u043c\u043e\u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u043e\u043b\u0443:\n        await _tableSemaphore.WaitAsync();\n        if (forks[Left(i)] == 0 &amp;&amp; forks[Right(i)] == 0)\n        {\n            forks[Left(i)] = i+1;\n            forks[Right(i)] = i+1;\n            hasForks = true;\n        }\n        _tableSemaphore.Release();\n        \/\/ \u0411\u0443\u0434\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0441\u0435\u0434 \u043f\u043e\u043b\u043e\u0436\u0438\u043b \u0432\u0438\u043b\u043a\u0438:\n        if (!hasForks)\n            await _philosopherSemaphores[i].WaitAsync();\n    }\n}\n\n\/\/ \u0416\u0434\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0442\u043e\u043b\u0443 \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0432\u0438\u043b\u043a\u0438.\nasync Task PutForks(int i)\n{\n    await _tableSemaphore.WaitAsync();\n    forks[Left(i)] = 0;\n    \/\/ \"\u041f\u0440\u043e\u0431\u0443\u0434\u0438\u0442\u044c\" \u0441\u043e\u0441\u0435\u0434\u0435\u0439, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \"\u0441\u043f\u0430\u043b\u0438\".\n    _philosopherSemaphores[LeftPhilosopher(i)].Release();\n    forks[Right(i)] = 0;\n    _philosopherSemaphores[RightPhilosopher(i)].Release();\n    _tableSemaphore.Release();\n}<\/code><\/pre>\n<p><\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0441 <code>async<\/code> \/ <code>await<\/code> \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0445\u0438\u0442\u0440\u044b\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0432\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 <code>Task<\/code>. \u0427\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0436\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u043e\u0442\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0438 \u0432\u0441\u0451 \u043f\u0440\u043e\u0447\u0435\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 Task. \u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435. \u0421\u0443\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438, \u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435, \u0430 \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u043f\u043e\u0442\u043e\u043a \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f. \u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442. \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438\u0437 \u044d\u0442\u0438\u0445 <code>async<\/code> \/ <code>await<\/code> \u043c\u0435\u0442\u043e\u0434\u043e\u0432. <\/p>\n<p><\/p>\n<p>\u041f\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c. \u0420\u0430\u0431\u043e\u0442\u0430 100 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 4 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u044f\u0434\u0440\u0430\u043c\u0438, 8 \u0441\u0435\u043a\u0443\u043d\u0434. \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 Monitor \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e \u0442\u043e\u043b\u044c\u043a\u043e 4 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 4 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u043b \u043e\u043a\u043e\u043b\u043e 2\u043c\u0441. \u0410 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 async \/ await \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e \u0432\u0441\u0435 100, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0436\u0434\u0430\u043b 6.8 \u0441\u0435\u043a\u0443\u043d\u0434. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e 6 \u0441\u0435\u043a\u0443\u043d\u0434 \u043d\u0435\u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e \u0438 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0442\u0430\u043a. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0436\u0435 \u0441 Monitor \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0432\u043e\u043e\u0431\u0449\u0435.<\/p>\n<p><\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u044d\u0442\u0438\u0445 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, .NET \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u041d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439. \u041f\u043e\u043a\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c, \u043d\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, TPL Dataflow, Reactive \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, Software Transaction \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0434\u0440. <\/p>\n<p><\/p>\n<h2 id=\"istochniki\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h2>\n<p><\/p>\n<ul>\n<li>\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432: <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/profiling\/concurrency-visualizer\">Concurrency Visualizer<\/a><\/noindex><\/li>\n<li>MSDN: <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/threading\/\">Threading<\/a><\/noindex>, <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/asynchronous-programming-patterns\/\">Asynchronous programming patterns<\/a><\/noindex> \u0438 \u043c\u043d. \u0434\u0440.<\/li>\n<li>[\u0420\u0438\u0445\u0442\u0435\u0440] \u2014 CLR via C#, Jeffrey Richter<\/li>\n<li>[\u042d\u0440\u0438\u043a \u041b\u0438\u043f\u043f\u0435\u0440\u0442] \u2014 <noindex><a rel=\"nofollow\" href=\"https:\/\/blogs.msdn.microsoft.com\/ericlippert\/2009\/03\/06\/locks-and-exceptions-do-not-mix\/\">\u041e lock<\/a><\/noindex><\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/artkpv\/dotnetconcurrency\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/noindex><\/li>\n<li>\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u2014 &#171;\u0422\u0430\u043d\u0435\u0446 \u0441\u0440\u0435\u0434\u0438 \u043c\u0435\u0447\u0435\u0439&#187;, \u0413. \u0421\u0435\u043c\u0438\u0440\u0430\u0434\u0441\u043a\u0438\u0439<\/li>\n<\/ul>\n<p>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/447898\/\">habr.com<\/a><\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 .Net, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0431\u0435\u0434\u0430\u044e\u0449\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432. \u041f\u043b\u0430\u043d \u0442\u0430\u043a\u043e\u0439, \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0434\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445). \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f. \u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u043c\u0435\u0442\u044c \u044d\u0442\u043e? \u0422\u0440\u0430\u043d\u0437\u0438\u0441\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0437\u0430\u043a\u043e\u043d \u041c\u0443\u0440\u0430 \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":24559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-32782","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 .Net, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0431\u0435\u0434\u0430\u044e\u0449\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432. \u041f\u043b\u0430\u043d \u0442\u0430\u043a\u043e\u0439, \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0434\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445). \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f. \u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u043c\u0435\u0442\u044c \u044d\u0442\u043e? \u0422\u0440\u0430\u043d\u0437\u0438\u0441\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0437\u0430\u043a\u043e\u043d \u041c\u0443\u0440\u0430 \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"de_DE\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0421\u044b\u0442\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 .NET | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 .Net, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0431\u0435\u0434\u0430\u044e\u0449\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432. \u041f\u043b\u0430\u043d \u0442\u0430\u043a\u043e\u0439, \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0434\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445). \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f. \u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u043c\u0435\u0442\u044c \u044d\u0442\u043e? \u0422\u0440\u0430\u043d\u0437\u0438\u0441\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0437\u0430\u043a\u043e\u043d \u041c\u0443\u0440\u0430 \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T18:48:54+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T18:48:54+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Satte Philosophen oder konkurrierende Programmierung in .NET | ProHoster","description":"Lassen Sie uns anschauen, wie konkurrierende und parallele Programmierung in .NET funktioniert, anhand des Problems der speisenden Philosophen. Der Plan ist, von der Synchronisation von Threads\/Prozessen bis hin zum Actor-Modell (in den folgenden Teilen) zu gehen. Der Artikel kann n\u00fctzlich sein f\u00fcr ein erstes Kennenlernen oder um Ihr Wissen aufzufrischen. Warum sollte man das \u00fcberhaupt k\u00f6nnen? Transistoren erreichen ihre minimale Gr\u00f6\u00dfe, das Mooresche Gesetz st\u00f6\u00dft an Geschwindigkeitsgrenzen.","canonical_url":"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"de_DE","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0421\u044b\u0442\u044b\u0435 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u044b \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 .NET | ProHoster","og:description":"\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e\u0435 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 .Net, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0431\u0435\u0434\u0430\u044e\u0449\u0438\u0445 \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u043e\u0432. \u041f\u043b\u0430\u043d \u0442\u0430\u043a\u043e\u0439, \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\/\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u0434\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445). \u0421\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0438\u043b\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f. \u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u043c\u0435\u0442\u044c \u044d\u0442\u043e? \u0422\u0440\u0430\u043d\u0437\u0438\u0441\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0437\u0430\u043a\u043e\u043d \u041c\u0443\u0440\u0430 \u0443\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438","og:url":"https:\/\/prohoster.info\/de\/blog\/administrirovanie\/sytye-filosofy-ili-konkurentnoe-programmirovanie-na-net","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T18:48:54+00:00","article:modified_time":"2019-10-31T18:48:54+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"32782","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-21 12:30:22","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 19:10:39","updated":"2026-01-21 12:30:22"},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts\/32782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/comments?post=32782"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/posts\/32782\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/media\/24559"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/media?parent=32782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/categories?post=32782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/de\/wp-json\/wp\/v2\/tags?post=32782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}