diff --git a/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs b/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs index e37607f1..69f196b1 100644 --- a/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs +++ b/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-02/src/main.rs @@ -4,13 +4,13 @@ use std::time::Duration; fn main() { let handle = thread::spawn(|| { for i in 1..10 { - println!("hi number {} from the spawned thread!", i); + println!("salom ochilgan threaddan {}-raqam!", i); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { - println!("hi number {} from the main thread!", i); + println!("salom, main threaddan {}-raqam!", i); thread::sleep(Duration::from_millis(1)); } diff --git a/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs b/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs index 0bccc5f5..f76e805d 100644 --- a/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs +++ b/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-04/src/main.rs @@ -4,7 +4,7 @@ fn main() { let v = vec![1, 2, 3]; let handle = thread::spawn(|| { - println!("Here's a vector: {:?}", v); + println!("Mana vektor: {:?}", v); }); drop(v); // oh no! diff --git a/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs b/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs index a6547dc4..81a8fc37 100644 --- a/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs +++ b/rustbook-uz/listings/ch16-fearless-concurrency/listing-16-05/src/main.rs @@ -4,7 +4,7 @@ fn main() { let v = vec![1, 2, 3]; let handle = thread::spawn(move || { - println!("Here's a vector: {:?}", v); + println!("Mana vektor: {:?}", v); }); handle.join().unwrap(); diff --git a/rustbook-uz/src/ch16-01-threads.md b/rustbook-uz/src/ch16-01-threads.md index 50c3d0b3..44042f96 100644 --- a/rustbook-uz/src/ch16-01-threads.md +++ b/rustbook-uz/src/ch16-01-threads.md @@ -174,28 +174,14 @@ Closuredan oldin `move` kalit so‘zini qo‘shish orqali biz closureni Rustga q Roʻyxat 16-5: `move` kalit soʻzidan foydalanib, closureni oʻzi foydalanadigan qiymatlarga ownershiplik qilishga majburlash -We might be tempted to try the same thing to fix the code in Listing 16-4 where -the main thread called `drop` by using a `move` closure. However, this fix will -not work because what Listing 16-4 is trying to do is disallowed for a -different reason. If we added `move` to the closure, we would move `v` into the -closure’s environment, and we could no longer call `drop` on it in the main -thread. We would get this compiler error instead: +Kodni 16 4 ro'yxatida tuzatish uchun xuddi shu narsani sinab ko'rishimiz mumkin, bu yerda main thread `move` closuresi orqali `drop` deb ataladi. Biroq, bu tuzatish ishlamaydi, chunki 16-4-raqamli roʻyxat boshqa sabablarga koʻra amalga oshirilmaydi. Agar biz closurega `move` ni qo‘shsak, biz `v` ni closure environmentiga o'tkazamiz va biz main threadda endi `drop` ni chaqira olmaymiz. Buning o'rniga biz ushbu kompilyator xatosini olamiz: ```console {{#include ../listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt}} ``` -Rust’s ownership rules have saved us again! We got an error from the code in -Listing 16-3 because Rust was being conservative and only borrowing `v` for the -thread, which meant the main thread could theoretically invalidate the spawned -thread’s reference. By telling Rust to move ownership of `v` to the spawned -thread, we’re guaranteeing Rust that the main thread won’t use `v` anymore. If -we change Listing 16-4 in the same way, we’re then violating the ownership -rules when we try to use `v` in the main thread. The `move` keyword overrides -Rust’s conservative default of borrowing; it doesn’t let us violate the -ownership rules. - -With a basic understanding of threads and the thread API, let’s look at what we -can *do* with threads. +Rustning ownershiplik(egalik) qoidalari bizni yana qutqardi! 16-3 roʻyxatdagi koddan xatoga yoʻl qoʻydik, chunki Rust konservativ boʻlib, thread uchun faqat `v` harfini oldi, bu esa main thread nazariy jihatdan ochilgangan threadning referenceni bekor qilishi mumkinligini anglatadi. Rustga `v` ownershiplik huquqini ochilgan threadga o'tkazishni aytish orqali biz Rustga main thread endi `v` dan foydalanmasligiga kafolat beramiz. Agar biz 16-4 ro'yxatni xuddi shunday o'zgartirsak, main threadda `v` dan foydalanmoqchi bo'lganimizda ownershiplik qoidalarini buzgan bo'lamiz. `move` kalit so'zi Rustning borrowing olishning konservativ defaultini bekor qiladi; ownershiplik qoidalarini buzishimizga yo'l qo'ymaydi. + +Threadar va thread API haqida asosiy tushunchaga ega bo'lgan holda, keling, threadlar bilan nima qilishimiz mumkinligini ko'rib chiqaylik. [capture]: ch13-01-closures.html#capturing-references-or-moving-ownership