Examples/tutorials for (the new) crossbeam

I am new to concurrent programming (closest I've done has been parallel programming using OpenMP). So I was wondering if there are any good examples or tutorials to learn different primitives in the newly released crossbeam crate.
For example

  • when it's best to use channels to share tasks/data between threads vs a global struct behind RwLock?
  • can the new data structures (ArrayQue, SeqQue, Deque) be shared across threads without a mutex? If not what's the recommended way of synchronizing the threads that use these data sturcutres?
  • When do I want to use AtomicCell to share data across threads vs using the global Injector in deque to achieve similar outocme? Does strategies that address these questions change if task are IO-bound?

I know some of these question may arise from my lack of knowledge in this area but I'm interested in finding some examples/tutorials that showcase the crate beyond sharing integers across threads?

Thanks

rayon is the gold standard for OpenMP-like parallelism in Rust. It works best if you can split your problem into sharing-nothing parts (data parallelism).

Data structures can be shared between threads if they're Send and Sync. The ones from crossbeam-channel can be shared.

You'll probably need to wrap shared collections in Arc to have them live in more than one thread at a time, unless they're cleverly cloneable themselves (e.g. im).

Yes, for I/O-bound you'll want Futures. There are futures-based thread pools to combine I/O-bound with CPU-bound.

2 Likes