{"id":315756,"date":"2020-12-29T15:02:07","date_gmt":"2020-12-29T15:02:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=315756"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=315756","title":{"rendered":"Rust \u0433\u043b\u0430\u0437\u0430\u043c\u0438 Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 #2"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/195\/686\/ed3\/195686ed398778209aa03e73615e17ee.jpg\" width=\"1200\" height=\"630\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043d\u043e\u0432\u0430 \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u044b \u2013 <a class=\"mention\" href=\"\/users\/cbmw\">@cbmw<\/a> \u0438 <a class=\"mention\" href=\"\/users\/andreyermilov\">@AndreyErmilov<\/a>, \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u00ab\u0420\u0430\u043c\u0431\u043b\u0435\u0440\/\u041c\u0435\u0434\u0438\u0430\u00bb (\u043f\u043e\u0440\u0442\u0430\u043b \u00ab\u0420\u0430\u043c\u0431\u043b\u0435\u0440\u00bb). \u0418 \u044d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0439 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f Python \u0438 Rust (<a href=\"https:\/\/habr.com\/ru\/company\/rambler_group\/blog\/533268\/\">\u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a>).<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0438\u043b\u0438 \u043b\u0435\u043d\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u044b\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f:<\/p>\n<p><iframe id=\"5fe8ad38d4323713fd415969\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/5fe8ad38d4323713fd415969\" class=\"embed_video embed__content\"><\/iframe><\/p>\n<h2>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Rust \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043c, \u043e \u0447\u0435\u043c \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u041e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u044b \u0435\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430, \u2013 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">import threading  x = 0  def increment_global():     global x     x += 1  def taskof_thread():     for _ in range(50000):         increment_global()  def main():     global x     x = 0     t1 = threading.Thread(target=taskof_thread)     t2 = threading.Thread(target=taskof_thread)     t1.start()     t2.start()     t1.join()     t2.join()   if __name__ == \"__main__\":     for i in range(5):         main()         print(\"x = {1} after Iteration {0}\".format(i, x))<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438\u00bb. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u0447\u0442\u043e \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u0412 \u043a\u043e\u0434\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0437\u0430\u043f\u0443\u0441\u043a \u0434\u0432\u0443\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0449\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430.<\/p>\n<p>\u041d\u0435\u0442\u0440\u0443\u0434\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0443\u0436\u0435 \u0441\u0447\u0438\u0442\u0430\u043b \u0441\u0442\u0430\u0440\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u043d\u043e \u043d\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u043e\u0432\u043e\u0435, \u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u2013 \u0435\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0442\u0440\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>\u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u0434:<\/p>\n<pre><code>$ python race.py x = 100000 after Iteration 0 x = 100000 after Iteration 1 x = 86114 after Iteration 2 x = 58422 after Iteration 3 x = 89266 after Iteration 4<\/code><\/pre>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e 2-\u044f, 3-\u044f \u0438 4-\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0430\u0434\u043e \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438\u00bb \u2013 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Mutex. \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u2013 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c Mutex \u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0440\u0435\u0434:<\/p>\n<pre><code class=\"python\">lock = threading.Lock() t1 = threading.Thread(target=taskof_thread, args=(lock,)) t2 = threading.Thread(target=taskof_thread, args=(lock,))<\/code><\/pre>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>taskof_thread<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0443\u044e\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\">def taskof_thread(lock):     for _ in range(50000):         lock.acquire()         increment_global()         lock.release()<\/code><\/pre>\n<p>\u041c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 <code>increment_global<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0432\u0437\u044f\u0442\u0438\u044f \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f Mutex \u0438 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u0436\u0434\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0432 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0447\u0438\u043d\u0438\u043b\u043e\u0441\u044c:<\/p>\n<pre><code>\u276f python race.py x = 100000 after Iteration 0 x = 100000 after Iteration 1 x = 100000 after Iteration 2 x = 100000 after Iteration 3 x = 100000 after Iteration 4<\/code><\/pre>\n<p>\u0414\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u041d\u0443 \u0438 \u043f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 Rust. \u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c Python-\u043a\u043e\u0434 \u00ab\u0432 \u043b\u043e\u0431\u00bb, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"rust\">use std::thread;  static mut X: i32 = 0;  fn increment_global() {     X += 1; }  fn thread_task() {     for _ in 0..50_000 {         increment_global()     } }  fn main_task() {     let t1 = thread::spawn(thread_task);      let t2 = thread::spawn(thread_task);       t1.join().unwrap();     t2.join().unwrap(); }  fn main() {     for i in 0..5 {         main_task();         println!(\"x = {} after Iteration {}\", X, i);     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 Python, \u0437\u0430 \u043e\u0434\u043d\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u2013 \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0435\u0433\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code>   Compiling playground v0.0.1 (\/playground) error[E0133]: use of mutable static is unsafe and requires unsafe function or block  --&gt; src\/main.rs:6:5   | 6 |     X += 1;   |     ^^^^^^ use of mutable static   |   = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior  error[E0133]: use of mutable static is unsafe and requires unsafe function or block   --&gt; src\/main.rs:26:47    | 26 |         println!(\"x = {} after Iteration {}\", X, i);    |                                               ^ use of mutable static    |    = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior  error: aborting due to 2 previous errors  For more information about this error, try `rustc --explain E0133`. error: could not compile `playground`.  To learn more, run the command again with --verbose.<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u043c \u043f\u0440\u044f\u043c\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>static mut <\/code>\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0433\u043e\u043d\u043a\u0438\u00bb. \u0414\u0430, \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 unsafe-\u0431\u043b\u043e\u043a\u0438 \u0438 \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0432 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u0434\u0430 \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0442\u0443\u0442, \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u044d\u0442\u0438\u043c. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043d\u0435\u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 Python-\u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>\u0422\u0443\u0442 \u044f\u0432\u043d\u043e \u0432\u0438\u0434\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 Python \u0438 Rust. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c Rust-\u0432\u0435\u0440\u0441\u0438\u044e \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f:<\/p>\n<pre><code class=\"rust\">use std::{sync::{Arc, Mutex}, thread}; use lazy_static::lazy_static; \/\/ 1.4.0  lazy_static! { static ref X: Mutex&lt;i32&gt; = Mutex::new(0); }  fn increment_global(x: &amp;Mutex&lt;i32&gt;) {     let mut data = x.lock().unwrap();     *data += 1; }  fn thread_task(x: &amp;Mutex&lt;i32&gt;) {     for _ in 0..50_000 {         increment_global(x)     } }  fn main_task(x: &amp;'static Mutex&lt;i32&gt;) {     let mut threads = vec![];     for _ in 0..2 {         threads.push(thread::spawn(move || thread_task(x)));     }     for thread in threads {         thread.join().unwrap();     } }  fn main() {     for i in 0..5 {         main_task(&amp;X);         let mut data = X.lock().unwrap();         println!(\"x = {} after Iteration {}\", data, i);     } }<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Mutex, \u043d\u043e \u0432 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0442\u0443\u0442 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435. \u0412 Rust Mutex \u2013 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f, \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u0442\u0435\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f. \u0412 Rust \u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u0442\u0435\u043c \u0432\u0437\u044f\u0442\u0438\u044f \u044d\u0442\u043e\u0433\u043e Mutex. \u041e\u043d \u043e\u0442\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f  \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c Mutex \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 Mutex, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a \u044d\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u0438\u043c\u0435\u0435\u0442. \u0412 Python \u044d\u0442\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c, \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0437\u0430 \u044d\u0442\u0438\u043c \u043b\u0435\u0436\u0438\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043d\u0430 \u043f\u043b\u0435\u0447\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.<\/p>\n<p>\u0414\u0430, \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0441 Python-\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c. \u041d\u0430 \u043d\u0430\u0448 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u043c\u0430\u043b\u043e\u0439 \u043f\u043b\u0430\u0442\u043e\u0439 \u0437\u0430 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c Rust.<\/p>\n<p>\u0415\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e <code>threading.Lock<\/code> \u0432 Python \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430, \u0447\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442 \u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. \u041a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043e\u043d \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u044d\u0442\u0438\u043c \u043b\u043e\u043a\u043e\u043c.<\/p>\n<p>\u041d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 Python \u0438 Rust \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f. \u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0442\u0438\u043f\u043e\u0432, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0433\u043e\u043d\u043a\u0438\u00bb, \u0445\u043e\u0442\u044f \u0438 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. <\/p>\n<p>\u041d\u043e \u0438 \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435. Rust \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e, \u0438 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u2013 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/rayon-rs\/rayon\">rayon<\/a>. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">fn main() {     let mut arr = [0, 7, 9, 11];     arr.iter_mut().for_each(|p| *p -= 1);     println!(\"{:?}\", arr); }<\/code><\/pre>\n<p>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">use rayon::prelude::*;  fn main() {     let mut arr = [0, 7, 9, 11];     arr.par_iter_mut().for_each(|p| *p -= 1);     println!(\"{:?}\", arr); }<\/code><\/pre>\n<h2>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0435\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e\u0431 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0449\u0438\u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0432 Python \u0438 Rust \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 (\u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e) \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043d\u0430 Python:<\/p>\n<pre><code class=\"python\">import asyncio   async def timers():     futures = []     for s in range(3):         futures.append(asyncio.sleep(s))     await asyncio.gather(*futures)  if __name__ == \"__main__\":     asyncio.run(timers())<\/code><\/pre>\n<p>\u0418 \u043d\u0430 Rust:<\/p>\n<pre><code class=\"rust\">use tokio::time::{delay_for, Duration}; use futures::future::join_all;  async fn timers() {     let futures = (0..2)         .map(Duration::from_secs)         .map(delay_for);     join_all(futures).await; }  #[tokio::main] async fn main() {     timers().await; }<\/code><\/pre>\n<p>\u041f\u043e \u043a\u043e\u0434\u0443 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041c\u044b \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0438 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0449\u0438\u043d\u044b, \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 Python \u043d\u0430 Rust \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0438, \u043e\u0442\u0447\u0430\u0441\u0442\u0438, \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0434\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a \u0431\u044b\u043b\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430: \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 Python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c async\/await \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043b\u0438\u0448\u044c \u0432 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 1.39.0, \u0432\u044b\u0448\u0435\u0434\u0448\u0435\u0439 7 \u043d\u043e\u044f\u0431\u0440\u044f 2019 \u0433\u043e\u0434\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u043c Rust \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<pre><code class=\"rust\">fn main() {     let addr = \"127.0.0.1:1234\".parse().unwrap();      let future = TcpStream::connect(&amp;addr)         .and_then(|socket| {             io::write_all(socket, b\"hello world\")         })         .and_then(|(socket, _)| {             \/\/ read exactly 11 bytes             io::read_exact(socket, vec![0; 11])         })         .and_then(|(socket, buf)| {             println!(\"got {:?}\", buf);             Ok(())         })         .map_err(|_| println!(\"failed\"));      tokio::run(future); }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043b\u044f \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u044b\u043a\u0448\u0438\u0445 \u043a async\/await Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0443\u0436\u0435\u0440\u043e\u0434\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u0438 \u043f\u043b\u044e\u0441\u044b, \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043c\u043d\u043e\u0433\u0438\u0435, \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438, \u0443\u0432\u0438\u0434\u044f\u0442 \u0432 \u044d\u0442\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u0433\u043e. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438 \u0441\u0435\u0439\u0447\u0430\u0441, \u043d\u0430\u0440\u044f\u0434\u0443 \u0441 <code>await<\/code> \u0432\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u0442\u044c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0432 Rust, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 Python, \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f <a href=\"https:\/\/tokio.rs\/tokio\/tutorial\/channels\">\u043a\u0430\u043d\u0430\u043b\u043e\u0432<\/a>.<\/p>\n<p>\u0418\u0437 \u0441\u0445\u043e\u0434\u0441\u0442\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 <code>event loop<\/code>-\u043e\u0432. \u041f\u0440\u0430\u0432\u0434\u0430, \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u044f\u0437\u044b\u043a\u043e\u0432 \u043d\u0435 \u043b\u0438\u0448\u0435\u043d \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430, \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0445 event loop.<\/p>\n<h2>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u0430<\/h2>\n<p>\u0412 \u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043d\u0435 \u0440\u0430\u0437 \u0443\u0436\u0435 \u043a\u0430\u0441\u0430\u043b\u0438\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u044f\u0437\u044b\u043a\u043e\u0432, \u0438 \u0432\u043e\u0442 \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u0447\u0443\u0442\u044c \u043f\u0440\u0438\u0441\u0442\u0430\u043b\u044c\u043d\u0435\u0435. \u041d\u0430 \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0442\u0443\u0442 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u2013 \u0441\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u0442\u0435\u043c\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u0435\u0437\u0434\u043e\u043d\u043d\u0430, \u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0435\u0435 \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u043f\u044b\u0442\u0430.<\/p>\n<h3>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0441\u0448\u0435\u0433\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0430<\/h3>\n<p>\u042d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0432 Python, \u0438 \u0432 Rust. \u041a\u0430\u043a \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c \u043f\u043e \u0445\u043e\u0434\u0443 \u0441\u0442\u0430\u0442\u044c\u0438, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">from typing import List, Callable   def map_each(list: List[str], fun: Callable[[str], int]) -&gt; List[int]:     new_array = []     for it in list:         new_array.append(fun(it))     return new_array  if __name__ == '__main__':     languages = [         \"Python\",         \"Rust\",         \"Go\",         \"Haskell\",     ]     out = map_each(languages, lambda it: len(it))     print(out)  # [6, 4, 2, 7]<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Python \u043c\u044b \u0441\u0440\u0430\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044c <code>typing<\/code> \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>map_each<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0443\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435: \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u2013 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 <code>Callable<\/code>-\u043e\u0431\u044a\u0435\u043a\u0442, \u0438\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u044f \u043f\u0440\u043e\u0449\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u041e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0443, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u2013 \u0447\u0438\u0441\u043b\u043e. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u043e.<\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0432 Rust:<\/p>\n<pre><code class=\"rust\">fn map_each(list: Vec&lt;string&gt;, fun: fn(&amp;String) -&gt; usize) -&gt; Vec&lt;usize&gt; {     let mut new_array: Vec&lt;usize&gt; = Vec::new();     for it in list.iter() {         new_array.push(fun(it));     }     return new_array; }  fn main() {     let list = vec![         String::from(\"Python\"),         String::from(\"Rust\"),         String::from(\"Go\"),         String::from(\"Haskell\"),     ];     let out = map_each(list, |it| it.len());      println!(\"{:?}\", out); \/\/ [6, 4, 2, 7] }<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u0445\u043e\u0436\u0435, \u043d\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e, \u0432\u0430\u0436\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435: Python \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0435 lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u042d\u0442\u043e \u0440\u0435\u0437\u043a\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u0414\u0430, \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0436\u0438\u0442\u044c, \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043d\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442.<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u0430\u0436\u043d\u044b\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u0435\u043c \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u00ab\u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432\u00bb. \u0412 Rust \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u2013 \u0447\u0430\u0441\u0442\u044c \u0442\u0440\u0435\u0439\u0442\u0430 Iterator, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0432 Python \u044d\u0442\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0440\u0435\u0439\u0442 Iterator \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0432\u0430\u0448\u0438\u0445 \u0442\u0438\u043f\u043e\u0432, \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0412 Rust \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0447\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"rust\">fn main() {     let list = vec![         Ok(42),         Err(\"Error - 1\"),         Ok(81),         Ok(88),         Err(\"Error - 2\")     ];      let out: Vec&lt;_&gt; = list         .iter()         .flatten()         .collect();      println!(\"{:?}\", out); \/\/ [42, 81, 88] }<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0438\u0437 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0445 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.  \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u043d\u0430\u043c Result \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0442\u0440\u0435\u0439\u0442 IntoIterator.  \u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Rust:<\/p>\n<pre><code class=\"rust\">fn main() {     let output = [\"42\", \"43\", \"sorokchetire\"]         .iter()         .map(|string| {                 string                  .parse::&lt;i32&gt;()                  .map_err(|_| println!(\"Parsing error\"))         })         .flatten()         .map(|integer| integer * 2)         .fold(0, |base, element| base + element);     println!(\"{:?}\", output); }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434  \u0443\u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435: \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 i32 \u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0432\u0430 \u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. <\/p>\n<p>\u0412 \u0447\u0435\u043c \u0436\u0435 \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a? \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>.fold<\/code>. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c map. \u0414\u0430, \u0432 Python \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f Comprehensions, \u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0433\u043e comprehension \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<h3>\u0417\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f<\/h3>\n<p>\u0421\u0430\u043c\u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u0432 Python, \u0438 \u0432 Rust. \u0412\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0442\u0438\u043f\u043e\u0432 Rust \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0432 Python.  \u041f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0438 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 Rust:<\/p>\n<pre><code class=\"rust\">fn main() {     let mut holder = vec![];      let sum = |a: usize, b: usize| -&gt; usize {         let c = a + b;         holder.push(a + b);         c     };      println!(\"{}\", sum(10, 20)); }<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043a\u043e\u0434, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 <code>sum<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0438\u0445.  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0435\u043a\u0442\u043e\u0440 <code>holder<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044f. \u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>holder<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u044e, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u043e\u043b\u0438\u0446\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0435\u0439\u0442 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0443\u0432\u0438\u0434\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"rust\">error[E0596]: cannot borrow `sum` as mutable, as it is not declared as mutable<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0438 \u043f\u043e\u043a\u0430 \u0441\u0430\u043c\u043e \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u043a\u0430\u043a <code>mut<\/code>. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"rust\">fn main() {     let mut holder = vec![];      let mut sum = |a: usize, b: usize| -&gt; usize {         let c = a + b;         holder.push(a + b);         c     };      println!(\"{}\", sum(10, 20)); }<\/code><\/pre>\n<p>\u0414\u0430, \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u0447\u0438\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0442\u0438\u043f\u043e\u0432 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u043d\u043e \u0437\u0430\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u0437\u0430\u043c\u044b\u043a\u0430\u043d\u0438\u0439 \u044f\u0432\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438 \u0441\u0432\u043e\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435, \u0447\u0442\u043e \u0443\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e. \u0425\u043e\u0442\u044f, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043c\u043d\u043e\u0433\u0438\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0442\u0443\u0442 \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0445\u043e\u0436\u0430 \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439 \u0441 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0438 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0432 Rust \u0438 Python. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 Rust \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u044f\u0432\u043d\u043e \u043f\u0440\u043e\u0441\u0438\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438, \u0430 \u043a\u0430\u043a\u0438\u0435 \u2013 \u043d\u0435\u0442. \u0427\u0442\u043e \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c, \u0447\u0435\u043c \u0442\u043e\u0442, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Python, \u0433\u0434\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c \u0442\u0438\u043f\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438, \u043f\u043e \u0441\u0443\u0442\u0438, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0435 \u043d\u0435\u043b\u044c\u0437\u044f.<\/p>\n<h3>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u044f<\/h3>\n<p>\u0418 \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043d\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435. \u0412 \u0446\u0435\u043b\u043e\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0441 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0435\u0439 \u0441\u0445\u043e\u0436\u0430 \u0432 \u043e\u0431\u043e\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445.  \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0445\u0432\u043e\u0441\u0442\u043e\u0432\u043e\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u043e \u0438 Rust, \u0438 Python. \u041e\u0434\u043d\u0430\u043a\u043e llvm (backend rust) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u044d\u0442\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.  \u0412\u043f\u043e\u043b\u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0442\u043e \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0432 Rust \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0438 \u044d\u0442\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u043a\u0440\u043e\u044e\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0432 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043f\u0440\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445. \u0412 Python <code>RecursionLimit<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412 Rust \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043a\u0430.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435: \u0417\u0430\u0447\u0435\u043c-\u0436\u0435 \u043f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u0443 Rust<\/h2>\n<p>\u041a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438, \u043f\u0438\u0442\u043e\u043d\u0438\u0441\u0442\u0443 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0442\u0438\u043f\u044b, \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 None, \u0430 \u0433\u0434\u0435 \u0447\u0438\u0441\u043b\u043e, \u0438\u0441\u043a\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043a\u0430\u043a\u0438\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u042d\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435. Mypy \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0438\u0445 \u0447\u0430\u0441\u0442\u0438, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Rust \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u0432 \u044d\u0442\u043e\u043c \u0443 mypy, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u043c\u0438 \u043a\u0430\u043c\u043d\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438. <\/p>\n<p>\u0423 Rust \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u043f\u043e\u0440\u043e\u0433 \u0432\u0445\u043e\u0434\u0430. \u0414\u043b\u044f \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0432\u044b\u0448\u0435, \u0438 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043a\u0430\u0441\u0430\u043b\u0438\u0441\u044c. \u0418 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435. \u0421\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0448\u044c \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438, \u043e\u043d\u0438 \u0443\u0436\u0435 \u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0438 \u043d\u0435 \u0442\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041d\u043e \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u043e\u0439\u0442\u0438, \u0438 \u044d\u0442\u043e\u0442 \u043f\u043e\u0440\u043e\u0433 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0442\u044c.<\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u0440\u0438\u0448\u043b\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0432\u044b\u0432\u043e\u0434\u0443: \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Python \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e. \u041d\u043e \u043f\u043e\u0442\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c, \u0432\u044b\u043b\u0435\u0437\u0430\u044e\u0442 \u0432\u0441\u0435 \u0442\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f Rust \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u0442\u0440\u0435\u0431\u0443\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043d\u043e \u0438 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043c \u0442\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0441\u0438\u043b\u0438\u0439 \u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0438 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/rambler_group\/blog\/535234\/\"> https:\/\/habr.com\/ru\/company\/rambler_group\/blog\/535234\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043d\u043e\u0432\u0430 \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u044b \u2013 <a class=\"mention\" href=\"\/users\/cbmw\">@cbmw<\/a> \u0438 <a class=\"mention\" href=\"\/users\/andreyermilov\">@AndreyErmilov<\/a>, \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u00ab\u0420\u0430\u043c\u0431\u043b\u0435\u0440\/\u041c\u0435\u0434\u0438\u0430\u00bb (\u043f\u043e\u0440\u0442\u0430\u043b \u00ab\u0420\u0430\u043c\u0431\u043b\u0435\u0440\u00bb). \u0418 \u044d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0439 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f Python \u0438 Rust (<a href=\"https:\/\/habr.com\/ru\/company\/rambler_group\/blog\/533268\/\">\u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a>).<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0438\u043b\u0438 \u043b\u0435\u043d\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u044b\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044f:<\/p>\n<p><iframe id=\"5fe8ad38d4323713fd415969\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/5fe8ad38d4323713fd415969\" class=\"embed_video embed__content\"><\/iframe><\/p>\n<h2>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Rust \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043c, \u043e \u0447\u0435\u043c \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u041e\u0434\u043d\u0430 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0438\u0434\u043d\u044b \u0435\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430, \u2013 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">import threading  x = 0  def increment_global():     global x     x += 1  def taskof_thread():     for _ in range(50000):         increment_global()  def main():     global x     x = 0     t1 = threading.Thread(target=taskof_thread)     t2 = threading.Thread(target=taskof_thread)     t1.start()     t2.start()     t1.join()     t2.join()   if __name__ == \"__main__\":     for i in range(5):         main()         print(\"x = {1} after Iteration {0}\".format(i, x))<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438\u00bb. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u0447\u0442\u043e \u0442\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u0412 \u043a\u043e\u0434\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0437\u0430\u043f\u0443\u0441\u043a \u0434\u0432\u0443\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0449\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430.<\/p>\n<p>\u041d\u0435\u0442\u0440\u0443\u0434\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0443\u0436\u0435 \u0441\u0447\u0438\u0442\u0430\u043b \u0441\u0442\u0430\u0440\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u043d\u043e \u043d\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u043e\u0432\u043e\u0435, \u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u2013 \u0435\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0442\u0440\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>\u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043a\u043e\u0434:<\/p>\n<pre><code>$ python race.py x = 100000 after Iteration 0 x = 100000 after Iteration 1 x = 86114 after Iteration 2 x = 58422 after Iteration 3 x = 89266 after Iteration 4<\/code><\/pre>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e 2-\u044f, 3-\u044f \u0438 4-\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041d\u0430\u0434\u043e \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438\u00bb \u2013 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Mutex. \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u2013 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0430\u043c Mutex \u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0440\u0435\u0434:<\/p>\n<pre><code class=\"python\">lock = threading.Lock() t1 = threading.Thread(target=taskof_thread, args=(lock,)) t2 = threading.Thread(target=taskof_thread, args=(lock,))<\/code><\/pre>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>taskof_thread<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0443\u044e\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\">def taskof_thread(lock):     for _ in range(50000):         lock.acquire()         increment_global()         lock.release()<\/code><\/pre>\n<p>\u041c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 <code>increment_global<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0432\u0437\u044f\u0442\u0438\u044f \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f Mutex \u0438 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u0436\u0434\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0443\u0436\u0435 \u0431\u044b\u043b\u0430 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0432 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0447\u0438\u043d\u0438\u043b\u043e\u0441\u044c:<\/p>\n<pre><code>\u276f python race.py x = 100000 after Iteration 0 x = 100000 after Iteration 1 x = 100000 after Iteration 2 x = 100000 after Iteration 3 x = 100000 after Iteration 4<\/code><\/pre>\n<p>\u0414\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e. \u041d\u0443 \u0438 \u043f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 Rust. \u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c Python-\u043a\u043e\u0434 \u00ab\u0432 \u043b\u043e\u0431\u00bb, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"rust\">use std::thread;  static mut X: i32 = 0;  fn increment_global() {     X += 1; }  fn thread_task() {     for _ in 0..50_000 {         increment_global()     } }  fn main_task() {     let t1 = thread::spawn(thread_task);      let t2 = thread::spawn(thread_task);       t1.join().unwrap();     t2.join().unwrap(); }  fn main() {     for i in 0..5 {         main_task();         println!(\"x = {} after Iteration {}\", X, i);     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 Python, \u0437\u0430 \u043e\u0434\u043d\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u2013 \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0435\u0433\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code>   Compiling playground v0.0.1 (\/playground) error[E0133]: use of mutable static is unsafe and requires unsafe function or block  --&gt; src\/main.rs:6:5   | 6 |     X += 1;   |     ^^^^^^ use of mutable static   |   = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior  error[E0133]: use of mutable static is unsafe and requires unsafe function or block   --&gt; src\/main.rs:26:47    | 26 |         println!(\"x = {} after Iteration {}\", X, i);    |                                               ^ use of mutable static    |    = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior  error: aborting due to 2 previous errors  For more information about this error, try `rustc --explain E0133`. error: could not compile `playground`.  To learn more, run the command again with --verbose.<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u043c \u043f\u0440\u044f\u043c\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>static mut <\/code>\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0433\u043e\u043d\u043a\u0438\u00bb. \u0414\u0430, \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u043d\u0443\u0436\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 unsafe-\u0431\u043b\u043e\u043a\u0438 \u0438 \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0432 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u0434\u0430 \u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0442\u0443\u0442, \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u044d\u0442\u0438\u043c. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043d\u0435\u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 Python-\u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>\u0422\u0443\u0442 \u044f\u0432\u043d\u043e \u0432\u0438\u0434\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 Python \u0438 Rust. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c Rust-\u0432\u0435\u0440\u0441\u0438\u044e \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f:<\/p>\n<pre><code class=\"rust\">use std::{sync::{Arc, Mutex}, thread}; use lazy_static::lazy_static; \/\/ 1.4.0  lazy_static! { static ref X: Mutex&lt;i32&gt; = Mutex::new(0); }  fn increment_global(x: &amp;Mutex&lt;i32&gt;) {     let mut data = x.lock().unwrap();     *data += 1; }  fn thread_task(x: &amp;Mutex&lt;i32&gt;) {     for _ in 0..50_000 {         increment_global(x)     } }  fn main_task(x: &amp;'static Mutex&lt;i32&gt;) {     let mut threads = vec![];     for _ in 0..2 {         threads.push(thread::spawn(move || thread_task(x)));     }     for thread in threads {         thread.join().unwrap();     } }  fn main() {     for i in 0..5 {         main_task(&amp;X);         let mut data = X.lock().unwrap();         println!(\"x = {} after Iteration {}\", data, i);     } }<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Mutex, \u043d\u043e \u0432 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0442\u0443\u0442 \u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435. \u0412 Rust Mutex \u2013 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f, \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u0442\u0435\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f. \u0412 Rust \u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u0442\u0435\u043c \u0432\u0437\u044f\u0442\u0438\u044f \u044d\u0442\u043e\u0433\u043e Mutex. \u041e\u043d \u043e\u0442\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f  \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438. <\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c Mutex \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 Mutex, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a \u044d\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u0438\u043c\u0435\u0435\u0442. \u0412 Python \u044d\u0442\u043e \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c, \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0437\u0430 \u044d\u0442\u0438\u043c \u043b\u0435\u0436\u0438\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043d\u0430 \u043f\u043b\u0435\u0447\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.<\/p>\n<p>\u0414\u0430, \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0441 Python-\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c. \u041d\u0430 \u043d\u0430\u0448 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u043c\u0430\u043b\u043e\u0439 \u043f\u043b\u0430\u0442\u043e\u0439 \u0437\u0430 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c Rust.<\/p>\n<p>\u0415\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e <code>threading.Lock<\/code> \u0432 Python \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430, \u0447\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442 \u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. \u041a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043e\u043d \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u044d\u0442\u0438\u043c \u043b\u043e\u043a\u043e\u043c.<\/p>\n<p>\u041d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 Python \u0438 Rust \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f. \u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0442\u0438\u043f\u043e\u0432, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u00ab\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0433\u043e\u043d\u043a\u0438\u00bb, \u0445\u043e\u0442\u044f \u0438 \u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. <\/p>\n<p>\u041d\u043e \u0438 \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435. Rust \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e, \u0438 \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u2013 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/rayon-rs\/rayon\">rayon<\/a>. \u041d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b, \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">fn main() {     let mut arr = [0, 7, 9, 11];     arr.iter_mut().for_each(|p| *p -= 1);     println!(\"{:?}\", arr); }<\/code><\/pre>\n<p>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">use rayon::prelude::*;  fn main() {     let mut arr = [0, 7, 9, 11];     arr.par_iter_mut().for_each(|p| *p -= 1);     println!(\"{:?}\", arr); }<\/code><\/pre>\n<h2>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0435\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e\u0431 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0449\u0438\u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0432 Python \u0438 Rust \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 (\u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e) \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043d\u0430 Python:<\/p>\n<pre><code class=\"python\">import asyncio   async def timers():     futures = []     for s in range(3):         futures.append(asyncio.sleep(s))     await asyncio.gather(*futures)  if __name__ == \"__main__\":     asyncio.run(timers())<\/code><\/pre>\n<p>\u0418 \u043d\u0430 Rust:<\/p>\n<pre><code class=\"rust\">use tokio::time::{delay_for, Duration}; use futures::future::join_all;  async fn timers() {     let futures = (0..2)         .map(Duration::from_secs)         .map(delay_for);     join_all(futures).await; }  #[tokio::main] async fn main() {     timers().await; }<\/code><\/pre>\n<p>\u041f\u043e \u043a\u043e\u0434\u0443 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041c\u044b \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0438 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0449\u0438\u043d\u044b, \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u044d\u0442\u043e \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 Python \u043d\u0430 Rust \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0438, \u043e\u0442\u0447\u0430\u0441\u0442\u0438, \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0434\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0430\u043a \u0431\u044b\u043b\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430: \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 Python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c async\/await \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043b\u0438\u0448\u044c \u0432 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 1.39.0, \u0432\u044b\u0448\u0435\u0434\u0448\u0435\u0439 7 \u043d\u043e\u044f\u0431\u0440\u044f 2019 \u0433\u043e\u0434\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u043e\u0434\u0430 \u043d\u0430\u0437\u0430\u0434. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u043c Rust \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<pre><code class=\"rust\">fn main() {     let addr = \"127.0.0.1:1234\".parse().unwrap();      let future = TcpStream::connect(&amp;addr)         .and_then(|socket| {             io::write_all(socket, b\"hello world\")         })         .and_then(|(socket, _)| {             \/\/ read exactly 11 bytes             io::read_exact(socket, vec![0; 11])         })         .and_then(|(socket, buf)| {             println!(\"got {:?}\", buf);             Ok(())         })         .map_err(|_| println!(\"failed\"));      tokio::run(future); }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043b\u044f \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u044b\u043a\u0448\u0438\u0445 \u043a async\/await Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0443\u0436\u0435\u0440\u043e\u0434\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u0438 \u043f\u043b\u044e\u0441\u044b, \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u0438, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043c\u043d\u043e\u0433\u0438\u0435, \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u044f\u0437\u044b\u043a\u0430\u043c\u0438, \u0443\u0432\u0438\u0434\u044f\u0442 \u0432 \u044d\u0442\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u043e\u0433\u043e. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438 \u0441\u0435\u0439\u0447\u0430\u0441, \u043d\u0430\u0440\u044f\u0434\u0443 \u0441 <code>await<\/code> \u0432\u044b \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0447\u0435\u0442\u0430\u0442\u044c \u043e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u041f\u043e\u043c\u0438\u043c\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0432 Rust, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 Python, \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f <a href=\"https:\/\/tokio.rs\/tokio\/tutorial\/channels\">\u043a\u0430\u043d\u0430\u043b\u043e\u0432<\/a>.<\/p>\n<p>\u0418\u0437 \u0441\u0445\u043e\u0434\u0441\u0442\u0432 \u043c\u043e\u0436\u043d\u043e<\/p>\n<\/div>\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-315756","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/315756","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=315756"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/315756\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}