On this page
  1. mpsc
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

mpsc

Prev: `RwLock` | Up: sync | Next: `OnceLock`
Rel: sync, rust/builtins
Ref: Rust std — mpsc
Tags: #public #prog #rust #stdlib #sync #tier/core


Signature & Overview

mpsc::channel::<T>()  /* + sync_channel(bound) */

Multi-producer, single-consumer FIFO channel for message passing between threads.

Notes & Pitfalls

Example

use std::sync::mpsc;
use std::thread;

fn main() {
    let (tx, rx) = mpsc::channel();
    thread::spawn(move || { tx.send("ping").unwrap(); }).join().unwrap();
    assert_eq!(rx.recv().unwrap(), "ping");
}

Linked from

Related notes