This week, the Rust team announced the release of Rust 1.63.

One notable update? Adding covered threads to the standard library:

Rust code can launch new threads from std::thread::spawn since 1.0, but this feature limits its closure with ‘static. Roughly speaking, this means that threads must now have ownership of any arguments passed to their closure; you cannot pass borrowed data to a stream. In cases where threads are expected to exit before the end of the function (being join()‘d), this is not strictly necessary and may require workarounds such as placing the data in the Ark.

Now, as of 1.63.0, the standard library adds scoped threads that allow spawning a thread borrowed from a local stack frame. The std::thread::scope The API provides the necessary guarantee that any created streams will exit before the very return, allowing data to be borrowed safely.
The official Rust RFC book says, “The main drawback is that scoped threads make the standard library a bit larger,” but calls it “a very common and useful utility…great for training, testing, and exploratory programming.”

“Every person learning Rust will at some point encounter the interplay between borrowing and threading. A very important lesson to be learned is that threads can borrow local variables, but the standard library [didn’t] display it.” And otherwise, “Implementation of scoped threads is very difficult to get right, so it’s good to have a robust solution provided by the standard library.”

Source by [author_name]

Previous articleA nine-year-old boy who fled war-torn Cyprus to London
Next articleIndependence Day: How Chicago Radio Became the Voice of India’s Freedom