January 2019
Beginner to intermediate
554 pages
13h 31m
English
A thread that doesn't communicate or access data from the parent thread is not much. Let's take a very common pattern of using multiple threads to concurrently access items in a list to perform some computation. Consider the following code:
// thread_read.rsuse std::thread;fn main() { let nums = vec![0, 1, 2, 3, 4]; for n in 0..5 { thread::spawn(|| { println!("{}", nums[n]); }); }}
In the preceding code, we have 5 numbers in values and we spawn 5 threads where each one of them accesses the data in values. Let's compile this program:

Interesting ! The error makes sense if you think about it from a borrowing perspective. ...
Read now
Unlock full access