{"id":331678,"date":"2022-04-08T09:00:27","date_gmt":"2022-04-08T09:00:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=331678"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=331678","title":{"rendered":"<span>\u041f\u043e\u0447\u0435\u043c\u0443 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b \u0432 Rust \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/6g\/h8\/tb\/6gh8tbuxibo7x1e0vnknyrcrsgg.png\" data-src=\"https:\/\/habrastorage.org\/webt\/6g\/h8\/tb\/6gh8tbuxibo7x1e0vnknyrcrsgg.png\"\/><\/div>\n<p>  \u042f \u0447\u0430\u0441\u0442\u043e \u0441\u043b\u044b\u0448\u0443 \u043e\u0442 \u043f\u0440\u043e\u0431\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Rust \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0436\u0430\u043b\u043e\u0431\u044b \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Lock_(computer_science)\" rel=\"nofollow noopener noreferrer\">\u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b<\/a> \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043d\u0430 Rust Mutex API. \u0416\u0430\u043b\u043e\u0431\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\u041e\u043d\u0438 \u043d\u0435 \u0445\u043e\u0442\u044f\u0442, \u0447\u0442\u043e\u0431\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443.<\/li>\n<li>\u041e\u043d\u0438 \u043d\u0435 \u0445\u043e\u0442\u044f\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u00ab\u0437\u0430\u0449\u0438\u0442\u043d\u044b\u043c\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u043f\u0440\u0438 \u0441\u0431\u0440\u043e\u0441\u0435, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043e\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u044f\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>unlock<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u044f\u0432\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435.<\/li>\n<\/ul>\n<p>  \u0422\u0430\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0438 \u0431\u044b Rust mutex API \u0432 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 C\/Posix mutex API. \u041e\u0434\u043d\u0430\u0436\u0434\u044b \u044f \u0434\u0430\u0436\u0435 \u0432\u0438\u0434\u0435\u043b, \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Mutex&lt;()><\/code> \u0438 \u0440\u0430\u0437\u043d\u044b\u0435 \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0440\u0435\u043c\u043b\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u044d\u0442\u0438 \u0434\u0432\u0430 \u0430\u0441\u043f\u0435\u043a\u0442\u0430 <code>Mutex<\/code> \u043d\u0435\u0440\u0430\u0437\u0440\u044b\u0432\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f\u043c\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 Rust \u0432 \u0446\u0435\u043b\u043e\u043c \u2014 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0438\u043b\u0438 \u043e\u0431\u043e\u0438\u0445 \u043e\u0442\u043a\u0440\u043e\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u044b\u0445 \u0431\u0430\u0433\u043e\u0432 \u0438 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 \u0438\u0437-\u0437\u0430 \u0433\u043e\u043d\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432 \u0432 \u0441\u0442\u0438\u043b\u0435 C, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>lock<\/code> \u0438 <code>unlock<\/code> \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0440\u043e\u043c\u0435\u0442\u0447\u0438\u0432\u044b\u043c \u0432 Rust, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043b\u0435\u0433\u043a\u043e \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0449\u0438\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041f\u0440\u043e\u0437\u0432\u0443\u0447\u0438\u0442 \u0441\u043f\u043e\u0440\u043d\u043e, \u043d\u043e \u044f \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e, \u0447\u0442\u043e <em>\u044d\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0438 \u0434\u043b\u044f C<\/em>. \u041f\u0440\u043e\u0441\u0442\u043e \u0432 Rust \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Rust \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u00ab\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e\u00bb \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438 \u00ab\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e\u00bb \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <em>\u043c\u043e\u0436\u043d\u043e<\/em> \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u0412 C \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u0442, \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b \u043a\u043e\u0434 \u043d\u0430 C \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0435 \u0431\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0442\u044c \u044d\u043a\u0441\u043f\u043b\u043e\u0439\u0442\u0430\u043c.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0443 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 C mutex API, \u0441\u0440\u0430\u0432\u043d\u044e \u0435\u0433\u043e \u0441 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u043c Rust mutex API, \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c Rust API \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043b C.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u041c\u044c\u044e\u0442\u0435\u043a\u0441\u044b \u0432 C<\/h1>\n<p>  (\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043a\u043e\u0433\u0434\u0430 \u044f \u0433\u043e\u0432\u043e\u0440\u044e \u00abC\u00bb, \u043c\u043e\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0438 \u043a \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c C, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u043a C++, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0441\u0443\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u043e \u0436\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432.)<\/p>\n<p>  \u0412 C \u0435\u0441\u0442\u044c \u0448\u0438\u0440\u043e\u043a\u0438\u0439 \u0432\u044b\u0431\u043e\u0440 API \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 API \u0431\u044b\u043b \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0451\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 2011 \u0433\u043e\u0434\u0443. \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b C11, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u044b \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u044c \u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438 \u043a <code>pthreads<\/code>.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e C mutex API \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439: <code>lock<\/code> \u0438 <code>unlock<\/code>. [\u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u0438\u0435 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432, \u0432\u0435\u0449\u0438 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>trylock<\/code>, \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432, \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435\u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438, \u0438 \u0442. \u0434. \u041d\u0438\u0447\u0442\u043e \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043c\u043e\u0438\u043c \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f\u043c.]<\/p>\n<pre><code class=\"cpp\">\/\/ \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u043f\u043e\u043a\u0430 \u043e\u043d \u043d\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442\u0441\u044f. int mtx_lock(mtx_t *mutex);  \/\/ \u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441. int mtx_unlock(mtx_t *mutex);<\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>int<\/code> \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>0<\/code>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u0443\u0441\u043f\u0435\u0445, \u0430 \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043d\u0435\u0443\u0434\u0430\u0447\u0443.<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445, \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>mtx_lock<\/code>. \u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>mtx_unlock<\/code>. \u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430, \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">mtx_t *the_mutex; int the_counter;  \/\/ \u041a\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 the_mutex \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d.  int increment_the_counter() {     int r = mtx_lock(the_mutex);     if (r != 0) return r;      \/\/ \u041f\u0440\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u043e\u043c.     the_counter++;      return mtx_unlock(the_mutex); }  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \"out-\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\", *value_out, \/\/ \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0443\u0441\u043f\u0435\u0445\/\u043d\u0435\u0443\u0434\u0430\u0447\u0443. int read_the_counter(int *value_out) {     int r = mtx_lock(the_mutex);     if (r != 0) return r;      \/\/ \u041f\u0440\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0447\u0451\u0442\u0447\u0438\u043a.     *value_out = the_counter;      return mtx_unlock(the_mutex); }<\/code><\/pre>\n<p>  \u0412 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u00ab\u043c\u0435\u043b\u043a\u0438\u0435\u00bb \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u043c\u044b\u043c\u0438 \u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">struct SomeData {     mtx_t *mutex;     int the_data; };<\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0449\u0438\u0449\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a\u0438\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043d\u0430 C \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u044b \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e\u0442 \u0438\u0437 <a href=\"https:\/\/www.chromium.org\/developers\/lock-and-condition-variable\/\" rel=\"nofollow noopener noreferrer\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Chromium \u043f\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c<\/a>:<\/p>\n<blockquote><p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0431\u0449\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439\/\u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u043a\u0430\u043a\u043e\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0435\u0451 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">int accesses_; \/\/ \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u0432 (\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0445 mu_)<\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0439, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"cpp\">int table_size_; \/\/ \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 (readonly \u043f\u043e\u0441\u043b\u0435 init)<\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439, \u043a\u0430\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0430\u043a\u0438\u0435 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043e\u043d \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">Lock mu_; \/\/ \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 accesses_, list_, count_           \/\/ \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442: count_ == \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u0432\u044f\u0437\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 list_<\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0440\u044f\u0434\u043e\u043c \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440; \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u043e\u0434\u0430.<\/p><\/blockquote>\n<p>  \u0425\u043e\u0442\u044f \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u044f \u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043d\u0438\u043a\u043e\u0433\u043e \u043d\u0435 \u0441\u0443\u0434\u0438\u0442\u044c, \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u0440\u043e\u043c\u043e\u043b\u0447\u0430\u0442\u044c \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0430\u0431\u0437\u0430\u0446\u0435. \u0415\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u0438\u043f\u0430\u043c\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u043f\u0440\u043e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432: \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c. \u042d\u0442\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044f \u0431\u043b\u0438\u0436\u0435 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u0430\u043a <code>void *<\/code> \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0430 \u043f\u043e\u0442\u043e\u043c \u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a.<\/p>\n<p>  \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u044f \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u043b\u0441\u044f \u043e\u0442 \u0442\u0435\u043c\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c Rust.<\/p>\n<h1>\u041c\u044c\u044e\u0442\u0435\u043a\u0441\u044b \u0432 Rust<\/h1>\n<p>  \u0412 \u043c\u043e\u0434\u0443\u043b\u0435 <code>std::sync<\/code> \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Rust \u0435\u0441\u0442\u044c \u0442\u0438\u043f <a href=\"https:\/\/doc.rust-lang.org\/std\/sync\/struct.Mutex.html\" rel=\"nofollow noopener noreferrer\"><code>Mutex<\/code><\/a>. \u0415\u0433\u043e API \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 API \u0432 C \u0442\u0440\u0435\u043c\u044f \u0430\u0441\u043f\u0435\u043a\u0442\u0430\u043c\u0438:<\/p>\n<ol>\n<li><code>Mutex<\/code> <em>\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442<\/em> \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435: \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u043c\u044f \u0442\u0438\u043f\u0430 <code>Mutex&lt;T><\/code>, \u0433\u0434\u0435 <code>T<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0439 \u0432\u0430\u043c\u0438 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0439 \u0442\u0438\u043f.<\/li>\n<li>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>lock<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u00ab\u0437\u0430\u0449\u0438\u0442\u043d\u043e\u0435\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/li>\n<li>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>unlock<\/code> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 <em>\u043d\u0435<\/em> \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e <code>Mutex<\/code>. (\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>unlock<\/code> \u0442\u0430\u043a\u0436\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>drop<\/code>, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0438\u0436\u0435.)<\/li>\n<\/ol>\n<p>  \u0412 bare-metal-\u0441\u0440\u0435\u0434\u0430\u0445 <code>no_std<\/code>, \u0433\u0434\u0435 \u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b <code>Mutex<\/code>, \u043d\u043e \u043e\u043d\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 <em>\u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a \u0436\u0435<\/em>, \u043a\u0430\u043a \u0438 <code>Mutex<\/code> \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0438 \u043d\u0430 \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u044b, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435.<\/p>\n<p>  \u0423\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f Rust API \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"rust\">\/\/ \u041c\u044c\u044e\u0442\u0435\u043a\u0441, \u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0449\u0438\u0439 \u043d\u0435\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 T. struct Mutex&lt;T> {     \/\/ \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e }  impl&lt;T> Mutex&lt;T> {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.     pub fn new(contents: T) -> Self { ... }      \/\/ \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441. \u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438     \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 MutexGuard, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u0441\u044b\u043b\u043a\u0443     \/\/ \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.     pub fn lock(&amp;self) -> MutexGuard&lt;'_, T> { ... } }  \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438'a, \/\/ \u043e\u0445\u0440\u0430\u043d\u044f\u044e\u0449\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u0430 T. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \/\/ Copy \u0438\u043b\u0438 Clone, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. struct MutexGuard&lt;'a, T> {     \/\/ \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e }<\/code><\/pre>\n<p>  (\u0412 \u044d\u0442\u043e\u043c \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e\u043c API \u044f \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00ablock poisoning\u00bb, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0430 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0442\u0435\u043c\u0435.)<\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0448\u0435\u0433\u043e API \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 Rust:<\/p>\n<pre><code class=\"rust\">\/\/ Rust-\u0432\u0435\u0440\u0441\u0438\u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \/\/ \u044d\u0442\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.  struct Counter {     mutex: Mutex&lt;usize>, }  fn increment_the_counter(ctr: &amp;Counter) {     let guard = ctr.mutex.lock();     *guard += 1;      \/\/ \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u044d\u0442\u043e \u043a\u0430\u043a     \/\/ *ctr.mutex.lock() += 1;     \/\/ \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u044c. }  fn read_the_counter(ctr: &amp;Counter) -> usize {     let guard = ctr.mutex.lock();     *guard }<\/code><\/pre>\n<p>  \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 API \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a: \u0442\u0438\u043f <code>MutexGuard<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>\u0443\u043c\u043d\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c<\/em>, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c\u0443 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0442\u0438\u043f\u0430 <code>T<\/code>, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043a\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0430\u043c\u0430 \u0437\u0430\u0449\u0438\u0442\u0430. \u041a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u044f\u0432\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u043b\u0438 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0441\u0432\u043e\u0435\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0434\u043e\u0441\u0442\u0443\u043f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u041d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u0438 \u0438\u043d\u0430\u0447\u0435: <code>MutexGuard<\/code> \u2014 \u044d\u0442\u043e \u0442\u043e\u043a\u0435\u043d, <em>\u0434\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439<\/em>, \u0447\u0442\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0431\u044b\u043b \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d.<\/p>\n<ul>\n<li>\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>MutexGuard<\/code> \u043d\u0438\u043a\u0430\u043a, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0435\u0439 <code>Mutex::lock<\/code>, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>MutexGuard<\/code> \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e <code>lock<\/code> \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430. [\u041f\u043e\u0434 \u044d\u0442\u0438\u043c \u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0438\u043a\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 <em>\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c<\/em> Rust, \u0438 \u043d\u0435\u043b\u044c\u0437\u044f \u043b\u0435\u0433\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e <em>\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e<\/em> \u0432 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c Rust. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c Rust \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043a\u0443\u0440\u0441\u0430 \u0438 \u0440\u0430\u0437\u0440\u0443\u0448\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u044f\u0437\u044b\u043a\u0430, \u043d\u043e \u044f \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u043f\u044b\u0442\u0430\u044e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u041f\u041e, \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0435 \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u043c \u0434\u043e\u0431\u0440\u043e\u0441\u043e\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0441 \u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0437\u043b\u043e\u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0432\u0430\u0440\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b, \u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 Rust \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>#![forbid(unsafe_code)]<\/code>. \u0410 \u043f\u043e\u0442\u043e\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0432\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043d\u0430\u0439\u043c\u0443 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0430.]<\/li>\n<li>\u0422\u0430\u043a \u043a\u0430\u043a <code>Mutex<\/code> \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043e\u0434\u0438\u043d <code>MutexGuard<\/code>, \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 <code>lock<\/code> \u043f\u0440\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 <code>MutexGuard<\/code> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d \u043f\u0435\u0440\u0432\u044b\u0439, \u0430 \u0441\u0430\u043c <code>MutexGuard<\/code> \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u2014 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>MutexGuard<\/code> \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 <em>\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439<\/em> \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c. \u0410 \u044d\u0442\u043e \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 Rust \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0437 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>&amp;mut T<\/code>.<\/li>\n<li>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 <code>'a<\/code> \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 <code>MutexGuard<\/code> \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u0441\u0430\u043c\u043e\u0433\u043e <code>Mutex<\/code>, \u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>lock<\/code> \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c <code>Mutex<\/code>, \u0432\u0441\u0451 \u0435\u0449\u0451 \u0438\u043c\u0435\u044e\u0449\u0438\u0439 <code>MutexGuard<\/code>, \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u044f \u0435\u0433\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0432 \u043f\u043e\u0432\u0438\u0441\u0448\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c.<\/li>\n<\/ul>\n<p>  <\/p>\n<h1>\u0412\u0430\u0440\u0438\u0430\u0446\u0438\u0438 Rust mutex API \u0438 \u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h1>\n<p>  \u041a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u0441\u0442\u0430, \u044f \u0441\u043b\u044b\u0448\u0443 \u0434\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0436\u0430\u043b\u043e\u0431\u044b \u043d\u0430 Rust mutex API.<\/p>\n<ol>\n<li>\u041c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430.<\/li>\n<li>\u041c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0449\u0438\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 (\u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>unlock<\/code>).<\/li>\n<\/ol>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438!<\/p>\n<h2>\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430<\/h2>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u044d\u0442\u043e\u0433\u043e. \u041f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u0438 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u0432 C:<\/p>\n<pre><code class=\"cpp\">struct SomeData {     mutex: Mutex&lt;()>,     the_data: i32, }<\/code><\/pre>\n<p>  (\u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0430\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 Rust \u0438 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043f\u043e\u043d\u044f\u0442\u0438\u0435\u043c \u00abinterior mutability\u00bb (\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c), \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432 \u044d\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0431\u0435\u0437 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u0432.)<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c, \u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043e\u0442 \u043e\u0434\u043d\u043e\u0439 \u0432\u0435\u0449\u0438: \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <code>the_data<\/code> \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430. \u041d\u0430\u0432\u0435\u0440\u043d\u043e, \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a\u0430\u043a \u0432 Chromium, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u0435, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 <code>SomeData<\/code>.<\/p>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439, \u043a\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u044d\u0442\u0438\u043c API \u0438 \u043d\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 (\u0438\u043b\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u043f\u043e\u043d\u044f\u043b) \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u043d\u0430 C. \u0412\u0435\u0434\u044c \u0442\u0430\u043a?<\/p>\n<p>  \u041a\u0430\u043a \u043d\u0438 \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u044d\u0442\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0433\u043e\u043d\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c Rust, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u0442\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">fn use_the_data_wrong(data: &amp;SomeData) -> i32 {     \/\/ \u042f \u043f\u043b\u043e\u0445\u043e\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0438 \u0431\u0443\u0434\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438     data.the_data }<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u0443\u044e \u0433\u043e\u043d\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0433\u043e\u043d\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043c\u044b \u043a\u043e\u0435-\u0447\u0442\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438: <em>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f <code>SomeData<\/code> \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/em><\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c <i>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/i> <code>SomeData<\/code> \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>SomeData<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>Sync<\/code>. <code>Sync<\/code> \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0442\u0438\u043f\u0430\u0436 (trait) Rust, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439, \u0447\u0442\u043e \u043d\u0435\u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u2014 \u0435\u0433\u043e \u0438\u043c\u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043d\u0435\u043a\u0443\u044e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e. <code>Sync<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u044b\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c, \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 <em>\u0442\u043e\u0436\u0435<\/em> \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c <code>Sync<\/code>, \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e <em>\u043e\u0431\u0449\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/em> \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043d\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 <em>\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/em>, \u0438 \u0435\u0441\u043b\u0438 <code>the_data<\/code> \u043f\u043e \u0441\u0443\u0442\u0438 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442 \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0435\u0451 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438. [\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043c\u043d\u043e\u0433\u043e\u044f\u0434\u0435\u0440\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u043c \u0441\u043e \u0441\u043b\u0430\u0431\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u043f\u0430\u043c\u044f\u0442\u0438, \u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0431\u0430\u0440\u044c\u0435\u0440\u044b. \u0415\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e\u0431 \u044d\u0442\u043e\u043c, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442.]<\/p>\n<p>  <code>i32<\/code> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 <em>\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0439<\/em> \u0430\u043d\u0430\u043b\u043e\u0433 <code>AtomicI32<\/code> (\u0438\u0437 <code>std::sync::atomic<\/code>). \u042d\u0442\u043e\u0442 \u0442\u0438\u043f <em>\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f<\/em> <code>Sync<\/code> \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0432\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043c\u044c\u044e\u0442\u0435\u043a\u0441! \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, <code>AtomicI32<\/code> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 <em>\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/em> \u2013 \u0435\u0433\u043e API \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0435\u0433\u043e.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c integer, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0438\u0437 integer \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439, \u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u0441\u0442\u0432\u043e, \u0442\u043e \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0430 \u0443 \u043d\u0438\u0445 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0438\u0445 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u0441 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0431\u044b\u043b <code>Sync<\/code>, \u0434\u0430\u0436\u0435 \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0442\u0438\u043f\u0430 <code>std::sync::Mutex<\/code>.<\/p>\n<p>  \u041d\u043e \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b <i>\u043d\u0435 \u0445\u043e\u0442\u0438\u043c<\/i> \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u043e\u0431\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u044c \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>Mutex<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u0443\u043c\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0435\u0441\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431.<\/p>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>SomeData<\/code> \u0432 \u043c\u043e\u0434\u0443\u043b\u044c, \u0441\u0434\u0435\u043b\u0430\u0432 \u0435\u0433\u043e \u043f\u043e\u043b\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u043d\u0435 \u043c\u043e\u0433 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <code>the_data<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u041c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 <code>SomeData<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043c\u044c\u044e\u0442\u0435\u043a\u0441. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u043c\u0443\u0447\u0430\u0442\u044c <code>Mutex&lt;()><\/code> \u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 <code>AtomicBool<\/code>.<\/p>\n<pre><code class=\"rust\">\/\/ \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430.  use std::sync::{AtomicBool, Ordering};  \/\/ Struct \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f pub; \u043f\u043e\u043b\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f pub. pub struct SomeData {     locked: AtomicBool,     the_data: i32, }  pub fn try_read_data(d: &amp;SomeData) -> Option&lt;i32> {     if d.locked.swap(true, Ordering::Acquire) {         \/\/ \u043c\u044b \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b!         None     } else {         \/\/ \u043c\u044b \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \"\u043c\u044c\u044e\u0442\u0435\u043a\u0441\" \u0438 \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435.         let result = d.the_data;         d.locked.store(false, Ordering::Release);         Some(result)     } }<\/code><\/pre>\n<p>  \u041d\u043e \u043c\u044b \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f <code>the_data<\/code> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438, <code>&amp;SomeData<\/code> \u2014 \u044d\u0442\u043e \u0432\u0441\u0451, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u043e\u0431\u0449\u0438\u043c \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<p>  \u0422\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 <code>Mutex<\/code> \u0438\u0433\u0440\u0430\u0435\u0442 <em>\u0434\u0432\u0435<\/em> \u0440\u043e\u043b\u0438 \u043e\u0442 \u043b\u0438\u0446\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0445 \u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0445: \u0434\u0430, \u043e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044d\u0442\u043e \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430, \u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>Cell<\/code> \u0438\u043b\u0438 <code>RefCell<\/code>.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0438 <code>Cell<\/code>, \u0438 <code>RefCell<\/code> \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <code>Sync<\/code> (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 <code>Mutex<\/code>), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f <code>the_data<\/code>, \u0438\u043b\u0438 \u043c\u044b <i>\u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e<\/i> \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0451 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0438\u0436\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>Cell<\/code>, <code>RefCell<\/code> \u0438 <code>Mutex<\/code>, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e <code>UnsafeCell<\/code>. \u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u0438\u043c\u0435\u043d\u0438, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0451\u043c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"rust\">\/\/ \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430.  use std::cell::UnsafeCell; use std::sync::{AtomicBool, Ordering};  \/\/ Struct \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f pub; \u043f\u043e\u043b\u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f pub. pub struct SomeData {     locked: AtomicBool,     the_data: UnsafeCell&lt;i32>, }  pub fn try_read_data(d: &amp;SomeData) -> Option&lt;i32> {     if d.locked.swap(true, Ordering::Acquire) {         \/\/ \u043c\u044b \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b!         None     } else {         \/\/ \u043c\u044b \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \"\u043c\u044c\u044e\u0442\u0435\u043a\u0441\"!         \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c: \u044d\u0442\u043e \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u0443\u0435\u0442         \/\/ \u0441\u044b\u0440\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0439 UnsafeCell::get. \u0427\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0431\u044b\u043b         \/\/ \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432\u0430\u043b\u0438\u0434\u0435\u043d, \u0447\u0442\u043e         \/\/ \u043d\u0430\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 UnsafeCell, \u0438 \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u0430\u044f \u043d\u0430\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430         \/\/ \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a \u0432\u0445\u043e\u0434\u0430\u043b\u0438 \u0438 \u0433\u043e\u043d\u043e\u043a, \u0432 \u0447\u0451\u043c \u043c\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u043d\u0430\u0432\u0435\u0440\u043d\u043e?         \/\/ \u0432\u0435\u0434\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0435\u0441\u0442\u044c?         let result = unsafe {             *d.the_data.get()         };         d.locked.store(false, Ordering::Release);         Some(result)     } }  pub fn try_write_data(d: &amp;SomeData, new_val: i32) -> bool {     if d.locked.swap(true, Ordering::Acquire) {         \/\/ \u043c\u044b \u0443\u0436\u0435 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u044b!         false     } else {         \/\/ \u043c\u044b \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \"\u043c\u044c\u044e\u0442\u0435\u043a\u0441\"!         \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c: \u0441\u043c. \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 try_read_data.         unsafe {             *d.the_data.get() = new_val;         }         d.locked.store(false, Ordering::Release);         true     } }  \/\/ \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u043c\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \/\/ \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. unsafe impl Sync for SomeData {}<\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>unsafe impl<\/code> \u0434\u043b\u044f <code>Sync<\/code>. \u042d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u043c\u044b \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043a <code>Sync<\/code> \u2026\u0431\u0435\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a. \u042d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>Sync<\/code> \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0441\u0435 <em>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u044b\u0435<\/em> \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>Sync<\/code> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u043c\u044b \u043c\u043e\u0436\u0435\u043c <em>\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c<\/em> \u0434\u0430\u043d\u043d\u044b\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. \u041c\u044b \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0435\u043c\u0441\u044f \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u0437\u0430\u043d\u043e\u0432\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0431\u041e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c <code>Mutex<\/code>\u2026 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0422\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <code>Mutex<\/code>, \u043d\u043e:<\/p>\n<ul>\n<li>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u0438\u0434 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439, \u0442\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0441\u043d\u043e\u0432\u0430.<\/li>\n<li>\u041d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c <em>\u0441\u0441\u044b\u043b\u043a\u0443<\/em> \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e.<\/li>\n<li>\u041d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u0438\u0445 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u041e\u0421, \u0430 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0451 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e.<\/li>\n<\/ul>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c <i>\u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435<\/i>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>try_lock<\/code>, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u0438 \u0441\u0434\u0435\u043b\u0430\u0432 \u0442\u0438\u043f \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u044b\u043c:<\/p>\n<pre><code class=\"rust\">struct SharedData&lt;T> {     owned: AtomicBool,     contents: UnsafeCell&lt;T>, }  impl&lt;T> SharedData&lt;T> {     pub fn try_lock(&amp;self) -> Option&lt;&amp;mut T> {         if self.owned.swap(true, Ordering::Acquire) {             \/\/ \u0443\u0436\u0435 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043e             None         } else {             \/\/ \u043c\u044b \u043f\u043e\u0431\u0435\u0434\u0438\u043b\u0438!             \/\/ \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c: \u044d\u0442\u043e\u0442 &amp;mut \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u0438\u0433\u0440\u0430\u043b\u0438 \u043b\u044e\u0431\u044b\u0435             \/\/ \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0433\u043e\u043d\u043a\u0438, \u0437\u0430\u0434\u0430\u0432 \u0444\u043b\u0430\u0433 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0433\u043e swap.             unsafe { &amp;mut *self.contents.get() }         }     } }  unsafe impl&lt;T: Send> Sync for SharedData&lt;T> {}<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0443\u0436\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0442\u0438\u043f <code>Mutex<\/code>, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 <code>unlock<\/code>.<\/p>\n<p>  <code>Mutex<\/code>-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u2014 \u044d\u0442\u043e \u0431\u0430\u0437\u0438\u0441 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u044f \u043d\u0430\u0437\u044b\u0432\u0430\u044e <a href=\"http:\/\/cliffle.com\/blog\/rust-first-mover\/\" rel=\"nofollow noopener noreferrer\">First-Mover Allocator Pattern<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0447\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 <code>Mutex<\/code>. \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430. \u041c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0437\u0430\u0449\u0438\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u043e \u0441\u0443\u0442\u0438 <em>\u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u0442\u044c<\/em> <code>std::sync::Mutex<\/code>, \u0438\u043b\u0438 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u043b\u043e\u0432\u0443\u0448\u043a\u0443, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<h2>\u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430<\/h2>\n<p>  \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0443\u0434\u0430\u043b\u0438\u043c <code>MutexGuard<\/code> \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e <code>Mutex<\/code> \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>unlock<\/code>, \u043a\u0430\u043a \u0432 C?<\/p>\n<p>  \u0412\u043e\u0442 \u043d\u0430\u0431\u0440\u043e\u0441\u043e\u043a \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 (\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437\u0431\u0435\u0436\u0438\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435):<\/p>\n<pre><code class=\"rust\">struct Mutex2&lt;T> {     \/\/ \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e }  impl&lt;T> Mutex2&lt;T> {     pub fn lock(&amp;self) -> &amp;mut T { ... }      pub fn unlock(&amp;self) { ... } }<\/code><\/pre>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043a\u0430\u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>MutexGuard<\/code> \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 <code>&amp;mut T<\/code>.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c API, \u043a\u0430\u043a \u0438 \u0432 C, \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>unlock<\/code> \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a <code>Mutex2<\/code>. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e <em>\u0434\u043e<\/em> \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<pre><code class=\"rust\">let guarded_data = mutex.lock(); guarded_data.do_stuff(); mutex.unlock();  guarded_data.do_stuff();  \/\/ \u043e\u0439-\u0451\u0439, \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/code><\/pre>\n<p>  \u0410 \u0435\u0449\u0451 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 <code>&amp;mut<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u0430, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0435\u0449\u0451 \u043e\u0434\u043d\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"rust\">let guarded_data = mutex.lock(); mutex.unlock(); let guarded_data2 = mutex.lock();  *guarded_data = *guarded_data2;  \/\/ \u043e\u0439-\u0451\u0439, \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b<\/code><\/pre>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438, \u043d\u0435\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u0430\u044f <code>unlock<\/code> \u0442\u0435\u0440\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u0434\u0430\u0451\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043c\u044b \u0441\u0442\u0440\u0435\u043c\u0438\u043c\u0441\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430.<\/p>\n<p>  \u0412 Rust \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>unlock<\/code> \u043d\u0430\u0434 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c \u0432 \u0441\u0442\u0438\u043b\u0435 C, \u043d\u043e \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c <code>unsafe<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <code>unlock<\/code> \u0438 <code>lock<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e, \u0447\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0443\u0442\u0435\u043a\u0443\u0442 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b <code>unlock<\/code>.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u043d\u0430\u0431\u0440\u043e\u0441\u043a\u0430 <code>Mutex2<\/code> \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u0435\u0433\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c! \u0418 \u043c\u044b \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>unlock<\/code> \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439, \u0430 \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a <code>unlock<\/code>, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>unlock<\/code> <em>\u043f\u043e\u0441\u043b\u0435<\/em> \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0438 <em>\u043f\u043e\u0441\u043b\u0435<\/em> \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043e\u0434\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0432\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0430 \u043d\u0435\u043a\u0438\u0439 \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0422\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432 <code>lock<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u0430\u043a-\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043c\u0435\u043d\u044f\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>unlock<\/code>, \u0438 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430. \u0412 Rust \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0441\u043e\u0437\u0434\u0430\u0432 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043b\u044c\u0437\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"rust\">struct Mutex2&lt;T> { ... }  impl&lt;T> Mutex2&lt;T> {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u0442\u043e\u043a\u0435\u043d _\u0438_ \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.     pub fn lock(&amp;self) -> (UnlockToken, &amp;mut T) { ... }      pub fn unlock(&amp;self, token: UnlockToken) { ... } }  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 Copy \u0438\u043b\u0438 Clone, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. struct UnlockToken { ... }<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u0434, \u0432\u044b\u0437\u0432\u0430\u0432\u0448\u0438\u0439 <code>lock<\/code>, \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>&amp;mut T<\/code> \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0435\u0433\u043e <code>UnlockToken<\/code>.<\/p>\n<p>  \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u043e\u0432\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c <code>UnlockToken<\/code>, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0434\u043d\u0438\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c, <em>\u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0443?<\/em> \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0432 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u0441 \u043a \u0433\u043e\u043d\u043a\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 <code>UnlockToken<\/code> \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043e\u0442 \u043a\u0430\u043a\u043e\u0433\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u043e\u043d \u0432\u0437\u044f\u0442 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c?), \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u043d\u0438\u043a\u0443, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0435\u0442 \u0441\u0432\u043e\u0438 \u0442\u043e\u043a\u0435\u043d\u044b. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0433\u043e\u043d\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u0441\u0440\u0435\u0434\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u043f\u0430\u043d\u0438\u043a\u0430), \u0447\u0442\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e.<\/p>\n<p>  \u041f\u043e\u043c\u0435\u0441\u0442\u0438\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0432\u043d\u0443\u0442\u0440\u044c <code>UnlockToken<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0441\u0440\u0435\u0434\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, <em>\u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0432<\/em> \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>unlock<\/code>. \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>unlock<\/code> <em>\u0432 \u0442\u043e\u043a\u0435\u043d<\/em>, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<pre><code class=\"rust\">struct Mutex2&lt;T> { ... }  impl&lt;T> Mutex2&lt;T> {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u0442\u043e\u043a\u0435\u043d _\u0438_ \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.     pub fn lock(&amp;self) -> (UnlockToken, &amp;mut T) { ... } }  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 Copy \u0438\u043b\u0438 Clone, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. struct UnlockToken { ... }  impl UnlockToken {     \/\/ \u042d\u0442\u043e \u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u043e, \u0441\u043c. \u043d\u0438\u0436\u0435.     pub fn unlock(self) { ... } }<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>UnlockToken::unlock<\/code> \u0431\u0435\u0440\u0451\u0442 <code>self<\/code> \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>self<\/code> \u2013 \u044d\u0442\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043d\u0430 \u0442\u043e\u043a\u0435\u043d. \u0422\u0430\u043a \u043a\u0430\u043a \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0442\u043e\u043a\u0435\u043d\u0430, \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e. \u042d\u0442\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443: \u0442\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 <code>unlock<\/code> \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>UnlockToken<\/code>, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0431\u0440\u043e\u0441\u0438\u0442 \u0442\u043e\u043a\u0435\u043d? \u0412 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c <em>\u043d\u0430\u0432\u0435\u0447\u043d\u043e<\/em>. \u042d\u0442\u043e \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 Rust \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e, \u043d\u043e <em>\u0431\u0443\u0434\u0435\u0442<\/em> \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0430\u0433\u0438. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <code>Drop<\/code> \u0434\u043b\u044f <code>UnlockToken<\/code>, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u044f \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>Drop<\/code> impl, \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0443\u044e \u043f\u0430\u043d\u0438\u043a\u0443.<\/li>\n<li>\u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>Drop<\/code> impl, \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043c\u044c\u044e\u0442\u0435\u043a\u0441.<\/li>\n<\/ul>\n<p>  \u0421\u043e\u0437\u0434\u0430\u044e\u0449\u0430\u044f \u043f\u0430\u043d\u0438\u043a\u0443 <code>Drop<\/code> impl \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u043e\u0432\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0440\u0435\u0434\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u0431\u0443\u0434\u0435\u0442 \u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0441\u0431\u0440\u043e\u0441 \u0442\u043e\u043a\u0435\u043d\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c <em>\u0431\u0430\u0433<\/em>. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0431\u0430\u0433, \u043f\u0430\u043d\u0438\u043a\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0437\u0443\u043c\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043e\u0442 \u0432\u043b\u0438\u044f\u043d\u0438\u044f \u0431\u0430\u0433\u0430. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u0430\u043d\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043a\u0430\u043f\u043a\u0430\u043d, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c.<\/p>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0441\u0431\u0440\u043e\u0441 \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043c\u0438 \u043d\u0430\u0431\u0440\u043e\u0441\u043a\u0435 API? \u0421\u0430\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"rust\">let (_, guarded_data) = mutex.lock(); guarded_data.do_stuff();<\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u043a\u0435\u043d\u0443 wildcard pattern <code>_<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u0431\u0440\u043e\u0448\u0435\u043d \u0441\u0440\u0430\u0437\u0443 \u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u043c. \u041f\u0430\u043d\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u0441\u0431\u0440\u043e\u0448\u0435\u043d, \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442 \u0434\u043e\u0441\u0442\u0443\u043f (\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0433\u043e\u043d\u043a\u0438), \u043d\u043e\u2026 \u0442\u043e\u043b\u044c\u043a\u043e <em>\u0432 \u044d\u0442\u043e\u043c<\/em> \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>  \u041d\u043e \u043d\u0435 \u0432 <em>\u044d\u0442\u043e\u043c<\/em>:<\/p>\n<pre><code class=\"rust\">let (token, guarded_data) = mutex.lock(); token.unlock(); guarded_data.do_stuff(); \/\/ \u043e\u0439-\u0451\u0439, \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u0430\u043d\u0438\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0433\u043e\u043d\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u042f \u0445\u043e\u0447\u0443 \u0434\u043e\u043d\u0435\u0441\u0442\u0438 \u043c\u044b\u0441\u043b\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u043f\u0430\u043d\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u0431\u0440\u043e\u0441\u0435 \u0442\u043e\u043a\u0435\u043d\u0430, \u0442\u043e\u043b\u044c\u043a\u043e <em>\u043e\u0442\u0432\u043b\u0435\u043a\u0430\u0435\u0442<\/em> \u043d\u0430\u0441 \u2014 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0435 \u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 (\u0445\u043e\u0442\u044f \u043b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0430\u043d\u0438\u043a\u0438 \u0438 \u044f \u0431\u044b \u0432\u044b\u0431\u0440\u0430\u043b \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u0438 \u0441\u0431\u0440\u043e\u0441\u0435). \u041d\u043e <em>\u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e<\/em> \u0438\u0437 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>unlock<\/code> \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439!<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0442\u043e\u043a\u0435\u043d\u0430 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0435 \u0436\u0438\u043b\u0430 \u0434\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0442\u043e\u043a\u0435\u043d \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438. \u041f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0438\u0445 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445. \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"rust\">struct Mutex2&lt;T> { ... }  impl&lt;T> Mutex2&lt;T> {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d \u0438 \u0441\u0441\u044b\u043b\u043a\u0443.     pub fn lock(&amp;self) -> MutexGuard&lt;'_, T> { ... } }  \/\/ \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 Copy \u0438\u043b\u0438 Clone, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. struct MutexGuard&lt;'a, T> { ... }  impl&lt;T> Drop for MutexGuard&lt;'a, T> {     \/\/ ... \u043a\u043e\u0434 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c }  \/\/ Deref \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c, \u043f\u043e\u043a\u0430 \u0436\u0438\u0432 MutexGuard. impl&lt;T> Deref for MutexGuard&lt;'a, T> {     type Target = T;     fn deref(&amp;self) -> &amp;Self::Target { ... } } \/\/ ... \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f DerefMut, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0443\u0449\u0435\u043d \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438.<\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u044b \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u043b\u0438 API <code>std::sync::Mutex<\/code>. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435:<\/p>\n<ol>\n<li>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0435\u0433\u043e \u043d\u0435 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0432, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>MutexGuard<\/code>.<\/li>\n<li>\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u043f\u0440\u0430\u0432\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>MutexGuard<\/code> \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/li>\n<li>\u0421\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 <code>MutexGuard<\/code> <i>\u0434\u043e\u043b\u0436\u0435\u043d<\/i> \u0432\u044b\u0439\u0442\u0438 \u0437\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>MutexGuard<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c.<\/li>\n<\/ol>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u044f\u0432\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b <code>unlock<\/code> \u0438\u043b\u0438 \u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u0441\u044f \u043d\u0430 <code>Drop<\/code>, \u0442\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, <em>\u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0447\u0435\u043d\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u043f\u0438\u0448\u0435\u0442\u0435 <code>unlock<\/code>.<\/em> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>unlock<\/code>, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041e\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"rust\">impl Mutex&lt;T> {     pub fn unlock(guard: MutexGuard&lt;'_, T>) {         \/\/ \u0417\u0434\u0435\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e --         \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0443\u0441\u0442\u0430\u044f!     } }<\/code><\/pre>\n<p>  \u0414\u0430, \u044d\u0442\u043e \u043f\u0443\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 <code>MutexGuard<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e. (\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 <code>std::mem::drop<\/code>, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e.) \u042d\u0442\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f <code>MutexGuard<\/code> \u0438 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e\u0439 \u0432 <code>MutexGuard<\/code>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>&amp;self<\/code>, \u0437\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e <code>Mutex<\/code>; \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"rust\">let guard = mutex.lock(); guard.do_stuff(); Mutex::unlock(guard);<\/code><\/pre>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0432\u0430\u043c \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043b\u044e\u0431\u0430\u044f <em>\u044f\u0432\u043d\u0430\u044f<\/em> \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c Rust, \u043f\u043e \u0441\u0443\u0442\u0438, \u043e\u0431\u044f\u0437\u0430\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a. (\u0418, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u043e\u043c <code>drop<\/code>.)<\/p>\n<p>  \u041b\u0438\u0447\u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u044f\u0432\u043d\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d:<\/p>\n<pre><code class=\"rust\">{     let guard = mutex.lock();     guard.do_stuff(); } \/\/ guard \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0437\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/code><\/pre>\n<p>  <\/p>\n<h1>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432 Rust API \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432 \u0432 \u0441\u0442\u0438\u043b\u0435 C, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0435\u0441\u044c \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 Rust, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0430\u0433\u043e\u0432 \u0433\u043e\u043d\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\/\u0438\u043b\u0438 \u0441\u043c\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 API \u043f\u043e\u0447\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <code>unsafe<\/code>. \u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e. \u041d\u0430\u0432\u0435\u0440\u043d\u043e, \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 concurrency.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0434\u0435\u0435\u0442\u0435\u0441\u044c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0447\u0438\u0442\u0430\u0435\u0442, \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0430 \u043f\u043e\u0442\u043e\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0451 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0442\u043e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0431\u0430\u0433\u0438.<\/p>\n<p>  \u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0430\u0443\u0434\u0438\u0442\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u2014 \u044f \u0438\u0449\u0443 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u043a\u043e\u0434\u0438\u043d\u0433\u0430 \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043f\u0440\u043e\u0446\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Chromium. \u041e\u043d\u0438 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u043b\u0438\u0437\u043b\u0435\u0436\u0430\u0449\u0438\u0439 API \u0438\u043c\u0435\u0435\u0442 \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0435 \u0438\u0437\u044a\u044f\u043d\u044b \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 Rust API \u0438\u043c\u0435\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c: \u043f\u043e\u0447\u0435\u043c\u0443 C mutex API \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e \u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0432\u0435\u0440\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438? \u0418 \u0432\u0441\u0451 \u044d\u0442\u043e \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 API \u0431\u044b\u043b \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 2010 \u0433\u043e\u0434\u0443, \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u043e\u0433\u043e\u044f\u0434\u0435\u0440\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u044b.<\/p>\n<p>  \u042d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432, \u0438 \u043d\u0435\u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432. \u0412 C (\u0438 C++) \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u0430\u0436\u043d\u044b\u0435 \u0444\u0438\u0447\u0438 \u044f\u0437\u044b\u043a\u0430, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c API \u0432 \u0441\u0442\u0438\u043b\u0435 Rust \u0441 \u0442\u0435\u043c\u0438 \u0436\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f\u043c\u0438 \u2014 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u044f\u0432\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438, \u043d\u0435\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0430 <code>Sync<\/code>, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u00abmove-\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430\u00bb \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u0441\u0432\u043e\u0451 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b (\u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 <code>MutexGuard<\/code>). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0440\u0430\u0437\u0443\u043c\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 C \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 API \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432.<\/p>\n<p>  \u0417\u0430\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0440\u0430\u0437\u0443\u043c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0448\u0435.<\/p><\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/659547\/\"> https:\/\/habr.com\/ru\/post\/659547\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/6g\/h8\/tb\/6gh8tbuxibo7x1e0vnknyrcrsgg.png\" data-src=\"https:\/\/habrastorage.org\/webt\/6g\/h8\/tb\/6gh8tbuxibo7x1e0vnknyrcrsgg.png\"\/><\/div>\n<p>  \u042f \u0447\u0430\u0441\u0442\u043e \u0441\u043b\u044b\u0448\u0443 \u043e\u0442 \u043f\u0440\u043e\u0431\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Rust \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u0436\u0430\u043b\u043e\u0431\u044b \u043d\u0430 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Lock_(computer_science)\" rel=\"nofollow noopener noreferrer\">\u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b<\/a> \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043d\u0430 Rust Mutex API. \u0416\u0430\u043b\u043e\u0431\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\u041e\u043d\u0438 \u043d\u0435 \u0445\u043e\u0442\u044f\u0442, \u0447\u0442\u043e\u0431\u044b \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443.<\/li>\n<li>\u041e\u043d\u0438 \u043d\u0435 \u0445\u043e\u0442\u044f\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u00ab\u0437\u0430\u0449\u0438\u0442\u043d\u044b\u043c\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u043f\u0440\u0438 \u0441\u0431\u0440\u043e\u0441\u0435, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043e\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u044f\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>unlock<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u044f\u0432\u043d\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435.<\/li>\n<\/ul>\n<p>  \u0422\u0430\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0438 \u0431\u044b Rust mutex API \u0432 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 C\/Posix mutex API. \u041e\u0434\u043d\u0430\u0436\u0434\u044b \u044f \u0434\u0430\u0436\u0435 \u0432\u0438\u0434\u0435\u043b, \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Mutex&lt;()><\/code> \u0438 \u0440\u0430\u0437\u043d\u044b\u0435 \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u0442\u0440\u0435\u043c\u043b\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u044d\u0442\u0438 \u0434\u0432\u0430 \u0430\u0441\u043f\u0435\u043a\u0442\u0430 <code>Mutex<\/code> \u043d\u0435\u0440\u0430\u0437\u0440\u044b\u0432\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u044f\u043c\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 Rust \u0432 \u0446\u0435\u043b\u043e\u043c \u2014 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0438\u043b\u0438 \u043e\u0431\u043e\u0438\u0445 \u043e\u0442\u043a\u0440\u043e\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u044b\u0445 \u0431\u0430\u0433\u043e\u0432 \u0438 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 \u0438\u0437-\u0437\u0430 \u0433\u043e\u043d\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 API \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u043e\u0432 \u0432 \u0441\u0442\u0438\u043b\u0435 C, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>lock<\/code> \u0438 <code>unlock<\/code> \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0440\u043e\u043c\u0435\u0442\u0447\u0438\u0432\u044b\u043c \u0432 Rust, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043b\u0435\u0433\u043a\u043e \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0430\u0440\u0443\u0448\u0430\u044e\u0449\u0438\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041f\u0440\u043e\u0437\u0432\u0443\u0447\u0438\u0442 \u0441\u043f\u043e\u0440\u043d\u043e, \u043d\u043e \u044f \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e, \u0447\u0442\u043e <em>\u044d\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0438 \u0434\u043b\u044f C<\/em>. \u041f\u0440\u043e\u0441\u0442\u043e \u0432 Rust \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Rust \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u00ab\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e\u00bb \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0438 \u00ab\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e\u00bb \u043a\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <em>\u043c\u043e\u0436\u043d\u043e<\/em> \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u0412 C \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u0442, \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b \u043a\u043e\u0434 \u043d\u0430 C \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u0435 \u0431\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0442\u044c \u044d\u043a\u0441\u043f\u043b\u043e\u0439\u0442\u0430\u043c.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0443 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 C mutex API, \u0441\u0440\u0430\u0432\u043d\u044e \u0435\u0433\u043e \u0441 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u043c Rust mutex API, \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c Rust API \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043b C.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-331678","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=331678"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/331678\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}