X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/1a691352b57b7338388ff568403495ecb44272eb..76de9227939c9244b1e5bd9364542c92991140c8:/src/part15.rs?ds=inline diff --git a/src/part15.rs b/src/part15.rs index 99eb3be..3b59825 100644 --- a/src/part15.rs +++ b/src/part15.rs @@ -11,7 +11,7 @@ use std::thread; //@ which we already discussed in a single-threaded context in part 12. //@ //@ ## `Mutex` -//@ The most basic type for interior mutability that supports concurrency is [`Mutex`](http://doc.rust-lang.org/stable/std/sync/struct.Mutex.html). +//@ The most basic type for interior mutability that supports concurrency is [`Mutex`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html). //@ This type implements *critical sections* (or *locks*), but in a data-driven way: One has to specify //@ the type of the data that's protected by the mutex, and Rust ensures that the data is *only* accessed //@ through the mutex. In other words, "lock data, not code" is actually enforced by the type system, which @@ -103,7 +103,7 @@ pub fn main() { // the data inside the lock. Change the code above to do that. Try using `unwrap_or_else` for this job. //@ ## `RwLock` -//@ Besides `Mutex`, there's also [`RwLock`](http://doc.rust-lang.org/stable/std/sync/struct.RwLock.html), which +//@ Besides `Mutex`, there's also [`RwLock`](https://doc.rust-lang.org/stable/std/sync/struct.RwLock.html), which //@ provides two ways of locking: One that grants only read-only access, to any number of concurrent readers, and another one //@ for exclusive write access. Notice that this is the same pattern we already saw with shared vs. mutable borrows. Hence //@ another way of explaining `RwLock` is to say that it is like `RefCell`, but works even for concurrent access. Rather than @@ -119,7 +119,7 @@ pub fn main() { //@ //@ In part 13, we talked about types that are marked `Send` and thus can be moved to another thread. However, we did *not* //@ talk about the question whether a borrow is `Send`. For `&mut T`, the answer is: It is `Send` whenever `T` is send. -//@ `&mut` allows moving values back and forth, it is even possible to [`swap`](http://doc.rust-lang.org/stable/std/mem/fn.swap.html) +//@ `&mut` allows moving values back and forth, it is even possible to [`swap`](https://doc.rust-lang.org/stable/std/mem/fn.swap.html) //@ the contents of two mutably borrowed values. So in terms of concurrency, sending a mutable borrow is very much like //@ sending full ownership, in the sense that it can be used to move the object to another thread. //@ @@ -144,4 +144,4 @@ pub fn main() { //@ [Rust RFC](https://github.com/rust-lang/rfcs/blob/master/text/0458-send-improvements.md), which contains a type `RcMut` that would be `Sync` and not `Send`. //@ You may also be interested in [this blog post](https://huonw.github.io/blog/2015/02/some-notes-on-send-and-sync/) on the topic. -//@ [index](main.html) | [previous](part14.html) | [next](part16.html) +//@ [index](main.html) | [previous](part14.html) | [raw source](https://www.ralfj.de/git/rust-101.git/blob_plain/HEAD:/workspace/src/part15.rs) | [next](part16.html)