Comprehensive Rust(日语) 202412
class on concurrency in Rust. We cover both classical concurrency (preemptively scheduling using threads and mutexes) and async/await concurrency (cooperative multitasking using futures). 本講座の対象外 Rust RefCell and Cell are !Sync, which means &RefCell and &Cell can't be passed between threads. This prevents two threads trying to access the cell at once. 22.5 演習: 健康に関する統計 健康管理システムの実装の一環として、ユーザーの健康に関する統計情報を追跡する必要があります。 SAFETY: There are no other threads which could be accessing `COUNTER`. unsafe { COUNTER += inc; } } fn main() { add_to_counter(42); // SAFETY: There are no other threads which could be accessing `COUNTER`0 码力 | 381 页 | 1.36 MB | 10 月前3Krita 5.2 マニュアル
make You can speed this up by enabling multithreading. To do so, you first figure out how many threads your processor can handle: cat /proc/cpuinfo | grep processor | wc -l Then, add the resulting number with a solution where our scheduler has two queues that it should spread between limited amount of threads. Of course there should be some algorithm that balances the queues. Ideally, we should balance them shared between all the threads so it should be written in a thread-safe way. In line (6) we apply a command sequentially, it means that it'll be executed right after all the threads with visitors has finished0 码力 | 1591 页 | 79.16 MB | 1 年前3
共 2 条
- 1