Shared-State Concurrency - The Rust Programming Language
Message passing is a fine way of handling concurrency, but it’s not the only one. Another method would be for multiple threads to access the same shared data. Consider this part of the slogan from the Go language documentation again: “do not communicate by sharing memory.” What would communicating by sharing memory look like? In addition, why would message-passing enthusiasts caution not to use memory sharing? In a way, channels in any programming language are similar to single ownership, because once you transfer a value down a channel, you should no longer use that value. Shared memory concurrency is like multiple ownership: multiple threads can access the same memory location at the same time. As you saw in Chapter 15, where smart pointers made multiple ownership possible, multiple ownership can add complexity because these different owners need managing. Rust’s type system and ownership rules greatly assist in getting this management correct. For an example, let’s look at mutexes,
Shared-State Concurrency - The Rust Programming Language Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Auto Light Rust Coal Navy Ayu The Rust Programming Language Shared-State Concurrency Message passing is a fine way to handle concurrency, but it’s not the only way. Another method would be for multiple threads to access the same shared data. Consider this part of the slogan from the Go language documentation again: “Do not communicate by sharing memory.” What would communicating by sharing
Explore this link on the map →related reading
- Transfer Data Between Threads with Message Passing - The Rust Programming Languagedoc.rust-lang.org
- Fearless Concurrency - The Rust Programming Languagedoc.rust-lang.org
- Using Threads to Run Code Simultaneously - The Rust Programming Languagedoc.rust-lang.org
- Mutex in std::sync - Rustdoc.rust-lang.org
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- Reading 14: Concurrencyweb.mit.edu
- What is Ownership? - The Rust Programming Languagedoc.rust-lang.org
- A half-hour to learn Rustfasterthanli.me
- Async Rust Is A Bad Languagebitbashing.io
- Reading 16: Mutual Exclusionweb.mit.edu
- The Scoped Task trilemmawithout.boats
- Rust Language Cheat Sheetcheats.rs