1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-22 07:47:44 +02:00

concurrency threads fa (#2297)

concurrency threads fa in the middle way for translation.

---------

Co-authored-by: javad-jafari <javajafarifromsharak@gmail.com>
Co-authored-by: javad-jafari <65780584+javad-jafari@users.noreply.github.com>
This commit is contained in:
Danny Khosravi 2024-08-21 00:47:03 +03:30 committed by GitHub
parent 3ecf12123b
commit e282cb2002
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6766,7 +6766,7 @@ msgstr ""
#: src/testing/unit-tests.md:32 src/testing/unit-tests.md:37 #: src/testing/unit-tests.md:32 src/testing/unit-tests.md:37
#: src/concurrency/threads/scoped.md:9 src/concurrency/threads/scoped.md:26 #: src/concurrency/threads/scoped.md:9 src/concurrency/threads/scoped.md:26
msgid "\"Hello\"" msgid "\"Hello\""
msgstr "" msgstr "\"سلام\""
#: src/std-types/string.md:9 #: src/std-types/string.md:9
msgid "\"s1: len = {}, capacity = {}\"" msgid "\"s1: len = {}, capacity = {}\""
@ -18090,177 +18090,215 @@ msgstr ""
#: src/concurrency/threads.md src/concurrency/shared-state.md #: src/concurrency/threads.md src/concurrency/shared-state.md
#: src/concurrency/async.md #: src/concurrency/async.md
msgid "This segment should take about 30 minutes. It contains:" msgid "This segment should take about 30 minutes. It contains:"
msgstr "" msgstr "این بخش باید حدود ۳۰ دقیقه طول بکشد و شامل موارد زیر است:"
#: src/concurrency/threads/plain.md:3 #: src/concurrency/threads/plain.md:3
msgid "Rust threads work similarly to threads in other languages:" msgid "Rust threads work similarly to threads in other languages:"
msgstr "" msgstr " threadهای Rust مانند threadها در زبان‌های دیگر کار می‌کنند:"
#: src/concurrency/threads/plain.md:12 #: src/concurrency/threads/plain.md:12
msgid "\"Count in thread: {i}!\"" msgid "\"Count in thread: {i}!\""
msgstr "" msgstr "\"شمارنده thread: {i}!\""
#: src/concurrency/threads/plain.md:18 #: src/concurrency/threads/plain.md:18
msgid "\"Main thread: {i}\"" msgid "\"Main thread: {i}\""
msgstr "" msgstr "\"Main thread: {i}\""
#: src/concurrency/threads/plain.md:24 #: src/concurrency/threads/plain.md:24
msgid "Threads are all daemon threads, the main thread does not wait for them." msgid "Threads are all daemon threads, the main thread does not wait for them."
msgstr "" msgstr "‏Thread‌ها همه daemon thread هستند و main thread منتظر آنها نیست."
#: src/concurrency/threads/plain.md:25 #: src/concurrency/threads/plain.md:25
msgid "Thread panics are independent of each other." msgid "Thread panics are independent of each other."
msgstr "" msgstr "Thread panicها مستقل از یکدیگر هستند."
#: src/concurrency/threads/plain.md:26 #: src/concurrency/threads/plain.md:26
msgid "Panics can carry a payload, which can be unpacked with `downcast_ref`." msgid "Panics can carry a payload, which can be unpacked with `downcast_ref`."
msgstr "" msgstr ""
"‏Panicها می‌تواند payloadای را حمل کند که می‌توان آن را با «downcast_ref» باز "
"کرد."
#: src/concurrency/threads/plain.md:31 #: src/concurrency/threads/plain.md:31
msgid "Rust thread APIs look not too different from e.g. C++ ones." msgid "Rust thread APIs look not too different from e.g. C++ ones."
msgstr "" msgstr ""
"‏Rust thread API ها خیلی متفاوت از موارد دیگر به نظر نمی‌رسند. که C++ یکی از "
"آن‌ها است."
#: src/concurrency/threads/plain.md:33 #: src/concurrency/threads/plain.md:33
msgid "Run the example." msgid "Run the example."
msgstr "" msgstr "مثال را اجرا کنید."
#: src/concurrency/threads/plain.md:34 #: src/concurrency/threads/plain.md:34
msgid "" msgid ""
"5ms timing is loose enough that main and spawned threads stay mostly in " "5ms timing is loose enough that main and spawned threads stay mostly in "
"lockstep." "lockstep."
msgstr "" msgstr ""
"زمان‌بندی 5 میلی‌ثانیه به اندازه‌ای سست هستند که thread اصلی و spawned threadها "
"عمدتاً همگام می‌مانند."
#: src/concurrency/threads/plain.md:36 #: src/concurrency/threads/plain.md:36
msgid "Notice that the program ends before the spawned thread reaches 10!" msgid "Notice that the program ends before the spawned thread reaches 10!"
msgstr "" msgstr ""
"توجه داشته باشید که برنامه قبل از اینکه thread spawned به مقدار ۱۰ برسد به "
"پایان می‌رسد!"
#: src/concurrency/threads/plain.md:37 #: src/concurrency/threads/plain.md:37
msgid "" msgid ""
"This is because main ends the program and spawned threads do not make it " "This is because main ends the program and spawned threads do not make it "
"persist." "persist."
msgstr "" msgstr ""
"این به خاطر است که انتهای main برنامه است و spawned threadها ایجاد شده باعث "
"تداوم آن نمی‌شوند."
#: src/concurrency/threads/plain.md:39 #: src/concurrency/threads/plain.md:39
msgid "Compare to pthreads/C++ std::thread/boost::thread if desired." msgid "Compare to pthreads/C++ std::thread/boost::thread if desired."
msgstr "" msgstr "در مقابسه با pthreads/C++ std::thread/boost::thread اگر مطلوب باشد."
#: src/concurrency/threads/plain.md:41 #: src/concurrency/threads/plain.md:41
msgid "How do we wait around for the spawned thread to complete?" msgid "How do we wait around for the spawned thread to complete?"
msgstr "" msgstr "چقدر باید صبر کنیم تا یک spawned thread تکمیل شود؟"
#: src/concurrency/threads/plain.md:42 #: src/concurrency/threads/plain.md:42
msgid "" msgid ""
"[`thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html) " "[`thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html) "
"returns a `JoinHandle`. Look at the docs." "returns a `JoinHandle`. Look at the docs."
msgstr "" msgstr ""
"[`thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html) "
"returns a `JoinHandle`. به سند نگاه کنید."
#: src/concurrency/threads/plain.md:43 #: src/concurrency/threads/plain.md:43
msgid "" msgid ""
"`JoinHandle` has a [`.join()`](https://doc.rust-lang.org/std/thread/struct." "`JoinHandle` has a [`.join()`](https://doc.rust-lang.org/std/thread/struct."
"JoinHandle.html#method.join) method that blocks." "JoinHandle.html#method.join) method that blocks."
msgstr "" msgstr ""
"`JoinHandle` دارد [`.join()`](https://doc.rust-lang.org/std/thread/struct."
"JoinHandle.html#method.join) متد آن بلاک‌ها."
#: src/concurrency/threads/plain.md:45 #: src/concurrency/threads/plain.md:45
msgid "" msgid ""
"Use `let handle = thread::spawn(...)` and later `handle.join()` to wait for " "Use `let handle = thread::spawn(...)` and later `handle.join()` to wait for "
"the thread to finish and have the program count all the way to 10." "the thread to finish and have the program count all the way to 10."
msgstr "" msgstr ""
"از «let handle = thread::spawn(...)» و بعد از «handle.join()» استفاده کنید "
"تا منتظر بمانید تا thread تمام شود و شمارنده برنامه برابر با مقدار ۱۰ باشد."
#: src/concurrency/threads/plain.md:48 #: src/concurrency/threads/plain.md:48
msgid "Now what if we want to return a value?" msgid "Now what if we want to return a value?"
msgstr "" msgstr "حالا اگر بخواهیم مقداری را برگردانیم چه؟"
#: src/concurrency/threads/plain.md:49 #: src/concurrency/threads/plain.md:49
msgid "Look at docs again:" msgid "Look at docs again:"
msgstr "" msgstr "دوباره به اسناد نگاه کنید:"
#: src/concurrency/threads/plain.md:50 #: src/concurrency/threads/plain.md:50
msgid "" msgid ""
"[`thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html)'s " "[`thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html)'s "
"closure returns `T`" "closure returns `T`"
msgstr "" msgstr ""
"[`thread::spawn`](https://doc.rust-lang.org/std/thread/fn.spawn.html)'s "
"closure returns `T`"
#: src/concurrency/threads/plain.md:51 #: src/concurrency/threads/plain.md:51
msgid "" msgid ""
"`JoinHandle` [`.join()`](https://doc.rust-lang.org/std/thread/struct." "`JoinHandle` [`.join()`](https://doc.rust-lang.org/std/thread/struct."
"JoinHandle.html#method.join) returns `thread::Result<T>`" "JoinHandle.html#method.join) returns `thread::Result<T>`"
msgstr "" msgstr ""
"`JoinHandle` [`.join()`](https://doc.rust-lang.org/std/thread/struct."
"JoinHandle.html#method.join) returns `thread::Result<T>`"
#: src/concurrency/threads/plain.md:53 #: src/concurrency/threads/plain.md:53
msgid "" msgid ""
"Use the `Result` return value from `handle.join()` to get access to the " "Use the `Result` return value from `handle.join()` to get access to the "
"returned value." "returned value."
msgstr "" msgstr ""
"به کمک`Result` از «handle.join()» برای دسترسی به مقدار برگشتی استفاده کنید."
#: src/concurrency/threads/plain.md:56 #: src/concurrency/threads/plain.md:56
msgid "Ok, what about the other case?" msgid "Ok, what about the other case?"
msgstr "" msgstr "خوب، مورد دیگر چطور؟"
#: src/concurrency/threads/plain.md:57 #: src/concurrency/threads/plain.md:57
msgid "Trigger a panic in the thread. Note that this doesn't panic `main`." msgid "Trigger a panic in the thread. Note that this doesn't panic `main`."
msgstr "" msgstr ""
"فعال‌سازی یک panic در یک thread. توجه شود که این مورد panic `main` نیست."
#: src/concurrency/threads/plain.md:58 #: src/concurrency/threads/plain.md:58
msgid "" msgid ""
"Access the panic payload. This is a good time to talk about [`Any`](https://" "Access the panic payload. This is a good time to talk about [`Any`](https://"
"doc.rust-lang.org/std/any/index.html)." "doc.rust-lang.org/std/any/index.html)."
msgstr "" msgstr ""
"دسترسی به این panic payload. بهترین زمان برای پرداخت به این موضوع است [`Any`]"
"(https://doc.rust-lang.org/std/any/index.html)."
#: src/concurrency/threads/plain.md:60 #: src/concurrency/threads/plain.md:60
msgid "Now we can return values from threads! What about taking inputs?" msgid "Now we can return values from threads! What about taking inputs?"
msgstr "" msgstr ""
"اکنون می‌توانیم مقادیر را از رشته‌ها برگردانیم! در مورد گرفتن ورودی‌ها چطور؟"
#: src/concurrency/threads/plain.md:61 #: src/concurrency/threads/plain.md:61
msgid "Capture something by reference in the thread closure." msgid "Capture something by reference in the thread closure."
msgstr "" msgstr "چیزی را از طریق reference در بسته‌بندی thread ثبت کنید."
#: src/concurrency/threads/plain.md:62 #: src/concurrency/threads/plain.md:62
msgid "An error message indicates we must move it." msgid "An error message indicates we must move it."
msgstr "" msgstr "یک پیغام خطا نشان می‌دهد که باید آن را جابجا کنیم."
#: src/concurrency/threads/plain.md:63 #: src/concurrency/threads/plain.md:63
msgid "Move it in, see we can compute and then return a derived value." msgid "Move it in, see we can compute and then return a derived value."
msgstr "" msgstr ""
"آن را به داخل منتقل کنید، درنتیجه ما می توانیم محاسبه کنیم و سپس یک مقدار "
"مشتق شده را برگردانیم."
#: src/concurrency/threads/plain.md:65 #: src/concurrency/threads/plain.md:65
msgid "If we want to borrow?" msgid "If we want to borrow?"
msgstr "" msgstr "اگر بخواهیم قرض (borrow) بگیریم چطور؟"
#: src/concurrency/threads/plain.md:66 #: src/concurrency/threads/plain.md:66
msgid "" msgid ""
"Main kills child threads when it returns, but another function would just " "Main kills child threads when it returns, but another function would just "
"return and leave them running." "return and leave them running."
msgstr "" msgstr ""
" تابع ‏Main در هنگام بازگشت threadهای فرزند را از بین می‌برد، اما تابع دیگری "
"return می‌شود و آنها را در حال اجرا می‌گذارد."
#: src/concurrency/threads/plain.md:68 #: src/concurrency/threads/plain.md:68
msgid "That would be stack use-after-return, which violates memory safety!" msgid "That would be stack use-after-return, which violates memory safety!"
msgstr "" msgstr ""
"این کار می‌تواند منجر به stack استفاده پس از return شود که memory safety را "
"نقض می‌کند!"
#: src/concurrency/threads/plain.md:69 #: src/concurrency/threads/plain.md:69
msgid "How do we avoid this? see next slide." msgid "How do we avoid this? see next slide."
msgstr "" msgstr "چگونه از آن جلوگیری کنیم؟ صفحه بعدی را ببینید."
#: src/concurrency/threads/scoped.md:3 #: src/concurrency/threads/scoped.md:3
msgid "Normal threads cannot borrow from their environment:" msgid "Normal threads cannot borrow from their environment:"
msgstr "" msgstr "‏thread‌های معمولی نمی‌توانند از محیط خود قرض (borrow) بگیرند:"
#: src/concurrency/threads/scoped.md:20 #: src/concurrency/threads/scoped.md:20
msgid "" msgid ""
"However, you can use a [scoped thread](https://doc.rust-lang.org/std/thread/" "However, you can use a [scoped thread](https://doc.rust-lang.org/std/thread/"
"fn.scope.html) for this:" "fn.scope.html) for this:"
msgstr "" msgstr ""
"به‌هرحال, می‌توانید برای این مورد [scoped thread](https://doc.rust-lang.org/"
"std/thread/fn.scope.html) ببینید:"
#: src/concurrency/threads/scoped.md:41 #: src/concurrency/threads/scoped.md:41
msgid "" msgid ""
"The reason for that is that when the `thread::scope` function completes, all " "The reason for that is that when the `thread::scope` function completes, all "
"the threads are guaranteed to be joined, so they can return borrowed data." "the threads are guaranteed to be joined, so they can return borrowed data."
msgstr "" msgstr ""
"دلیل آن این است که وقتی تابع «thread::scope» کامل می‌شود، اتصال همه thread‌ها "
"تضمین می‌شود، بنابراین می‌توانند داده‌های قرضی را برگردانند."
#: src/concurrency/threads/scoped.md:43 #: src/concurrency/threads/scoped.md:43
msgid "" msgid ""
"Normal Rust borrowing rules apply: you can either borrow mutably by one " "Normal Rust borrowing rules apply: you can either borrow mutably by one "
"thread, or immutably by any number of threads." "thread, or immutably by any number of threads."
msgstr "" msgstr ""
"قوانین عادی قرض‌گیری Rust اعمال می‌شود: شما می‌توانید به‌صورت تغییرپذیر(mutable) "
"با یک thread یا غیرقابل تغییر (immutable) با هر تعداد thread قرض (borrow) "
"بگیرید."
#: src/concurrency/channels.md src/concurrency/async-control-flow.md #: src/concurrency/channels.md src/concurrency/async-control-flow.md
msgid "This segment should take about 20 minutes. It contains:" msgid "This segment should take about 20 minutes. It contains:"
@ -18969,6 +19007,12 @@ msgid ""
"per-task overhead is typically very low and operating systems provide " "per-task overhead is typically very low and operating systems provide "
"primitives for efficiently identifying I/O that is able to proceed." "primitives for efficiently identifying I/O that is able to proceed."
msgstr "" msgstr ""
"‏ \"Async\" یک مدل concurrency است که در آن چندین کار به طور هم‌زمان با اجرای "
"هر کار تا زمانی که مسدود شود، اجرا می‌شود و سپس به کار دیگری که آماده ادامه "
"دادن است سوئیچ می‌شود. این مدل اجازه می‌دهد تا تعداد بیشتری کار را روی تعداد "
"محدودی از رشته‌ها اجرا کنید و به این دلیل است که سربار هر task معمولاً بسیار "
"کم است و سیستم‌‌عامل‌ها معمولاً مقدماتی را برای شناسایی مؤثر I/O که قادر به "
"ادامه هستند فراهم می‌کنند."
#: src/concurrency/welcome-async.md #: src/concurrency/welcome-async.md
msgid "" msgid ""
@ -18976,12 +19020,17 @@ msgid ""
"that may be completed in the future. Futures are \"polled\" until they " "that may be completed in the future. Futures are \"polled\" until they "
"signal that they are complete." "signal that they are complete."
msgstr "" msgstr ""
"عملیات Rust asynchronous بر اساس \"futures\" است، که نشان‌دهنده کاری است که "
"ممکن است در آینده تکمیل شود. future‌ها تا زمانی که علامت کامل بودنشان را "
"ندهند، «polled» می‌شوند."
#: src/concurrency/welcome-async.md #: src/concurrency/welcome-async.md
msgid "" msgid ""
"Futures are polled by an async runtime, and several different runtimes are " "Futures are polled by an async runtime, and several different runtimes are "
"available." "available."
msgstr "" msgstr ""
"‏ Futureها توسط یک زمان‌بندی ناهمزمان نظارت می‌شوند و چندین زمان‌بندی مختلف در "
"دسترس هستند."
#: src/concurrency/welcome-async.md #: src/concurrency/welcome-async.md
msgid "" msgid ""
@ -18989,6 +19038,9 @@ msgid ""
"callback-based, and not polled. Async Python programs require a \"loop\", " "callback-based, and not polled. Async Python programs require a \"loop\", "
"similar to a runtime in Rust." "similar to a runtime in Rust."
msgstr "" msgstr ""
"پایتون مدل مشابهی را در «asyncio» خود دارد. با‌این‌حال، تایپ «Future» آن مبتنی "
"بر callback است و poll نشده است. برنامه‌های Async Python به یک «حلقه» شبیه به "
"runtime در Rust نیاز دارند."
#: src/concurrency/welcome-async.md #: src/concurrency/welcome-async.md
msgid "" msgid ""
@ -18996,6 +19048,9 @@ msgid ""
"runtime implements the event loop, so many of the details of Promise " "runtime implements the event loop, so many of the details of Promise "
"resolution are hidden." "resolution are hidden."
msgstr "" msgstr ""
"این مورد شبیه \"Promise\" در جاوا اسکریپت است که دوباره مبتنی بر callback "
"است. runtime زبان حلقه رویداد (event loop) را پیاده سازی می‌کند، بنابراین "
"بسیاری از جزئیات واضح در Promise پنهان می‌شوند."
#: src/concurrency/async.md #: src/concurrency/async.md
msgid "async/await" msgid "async/await"