Skip to content
Select theme

Threads

A thread in Rust is a function that runs elsewhere and a handle you can wait on. The interesting part is what the compiler lets you send to it — which is Send, and which is why Rc will not go.

Nine articles, in the order the errors appear.

Nothing published in this chapter yet — all 9 articles are still to come.

Coming up (9)
  • How to start a threadthread::spawn and the JoinHandle
  • How to pass data to a threadthe move closure, and why it needs ’static
  • How to wait for a thread and get its resultjoin returns a Result too
  • How to share data between threads with Arcclone the Arc, not the data
  • What does it mean for a type to be thread safe?Send and Sync applied
  • How to fix “cannot be sent between threads safely”find the Rc or the RefCell
  • How many threads should you spawn?available_parallelism, and the pool you probably want
  • How to borrow data in a threadscope, and the lifetime that no longer needs ’static
  • How to recover from a panicked threadthe Err that join returns, and what is still alive