Tutorial by Examples

To start a new thread: use std::thread; fn main() { thread::spawn(move || { // The main thread will not wait for this thread to finish. That // might mean that the next println isn't even executed before the // program exits. println!("Hello from spa...
Channels can be used to send data from one thread to another. Below is an example of a simple producer-consumer system, where the main thread produces the values 0, 1, ..., 9, and the spawned thread prints them: use std::thread; use std::sync::mpsc::channel; fn main() { // Create a channel...
Session Types are a way to tell the compiler about the protocol you want to use to communicate between threads - not protocol as in HTTP or FTP, but the pattern of information flow between threads. This is useful since the compiler will now stop you from accidentally breaking your protocol and causi...
Atomic types are the building blocks of lock-free data structures and other concurrent types. A memory ordering, representing the strength of the memory barrier, should be specified when accessing/modifying an atomic type. Rust provides 5 memory ordering primitives: Relaxed (the weakest), Acquire (f...
RwLocks allow a single producer provide any number of readers with data while preventing readers from seeing invalid or inconsistent data. The following example uses RwLock to show how a single producer thread can periodically increase a value while two consumers threads are reading the value. use...

Page 1 of 1