Rs
Module 7Threads & ChannelsLesson 3 of 718 min

Sharing Read-Only Data

Arc for shared immutable inputs (spots, curves).

Arc

Atomic reference counted pointer — share owned data across threads.

rust
use std::sync::Arc;
let curve = Arc::new(vec![0.01, 0.015, 0.02]);
let c = Arc::clone(&curve);

Pattern

Share immutable market data with Arc; send results via channels.

Challenge

Share a strike Arc<f64> and compute call payoffs in each thread.

Tips
  • Arc::clone is cheap refcount
  • Immutable share is easy
  • Mutation needs Mutex

Try it live

Sharing Read-Only DataRust 2021
Loading editor…
Output
Press Run to compile and execute.