En bref. Déplacer une donnée dans un thread ne suffit pas toujours : encore faut-il que son type supporte le voyage, et le partage. Rust l’exprime avec deux traits marqueurs, Send et Sync, que le compilateur vérifie à chaque thread::spawn. Quand l’un manque, c’est E0277 : cannot be sent between threads safely, ou cannot be shared between threads safely. Et pour modifier une donnée depuis plusieurs threads, il faut deux pièces qui ne font pas le même travail : Arc et Mutex.
Le modèle en une phrase
Send: la valeur peut changer de thread.Sync: plusieurs threads peuvent la lire en même temps.Arcpartage la possession,Mutexrétablit l’exclusivité, un thread à la fois : aucun des deux ne suffit seul.
C’est la suite directe de l’article sur les threads et move, qui s’arrêtait sur cette phrase : « spawn exige aussi Send ».
In short. Moving data into a thread isn’t always enough: its type must also support the trip, and the sharing. Rust expresses this with two marker traits, Send and Sync, which the compiler checks on every thread::spawn. When one is missing, it’s E0277: cannot be sent between threads safely, or cannot be shared between threads safely. And to mutate data from several threads, you need two pieces that don’t do the same job: Arc and Mutex.
The model in one sentence
Send: the value can change threads.Sync: several threads can read it at the same time.Arcshares ownership,Mutexrestores exclusivity, one thread at a time: neither is enough alone.
It’s the direct sequel to the article on threads and move, which stopped on this sentence: “spawn also requires Send”.
let nom = Rc::new(String::from("Ada"));thread::spawn(move || println!("{nom}"));
spawnexige une closureSend: tout ce qu'elle emporte doit pouvoir changer de thread. UnRcne le peut pas : son compteur n'est pas atomique, et deux threads qui clonent en même temps le fausseraient. rustc refuse (E0277).spawnrequires aSendclosure: everything it takes along must be able to change threads. AnRccan't: its counter isn't atomic, and two threads cloning at the same time would corrupt it. rustc refuses (E0277).Arccompte avec des opérations atomiques : il estSendetSync, chaque thread reçoit son clone. Mais plusieurs propriétaires veut dire lecture seule :pushest refusé (E0596).Arcpartage, il ne permet pas de modifier.Arccounts with atomic operations: it isSendandSync, each thread gets its own clone. But several owners means read-only:pushis refused (E0596).Arcshares, it does not allow mutation.- Ajouter une
Cellpour modifier ?Cellmodifie à travers un&sans aucune protection : deux threads écriraient en même temps. Elle n'est pasSync, et unArc<T>n'estSendque siTestSync. E0277, côté partage cette fois.Add aCellto mutate?Cellmutates through a&with no protection at all: two threads would write at the same time. It isn'tSync, and anArc<T>is onlySendifTisSync. E0277, on the sharing side this time. Mutexapporte ce qui manquait : la modification à travers un&, mais un seul thread à la fois. Il estSync, doncArc<Mutex<T>>estSend.Arcpartage la possession,Mutexrétablit l'exclusivité : total 4000, aucune écriture perdue.Mutexbrings what was missing: mutation through a&, but one thread at a time. It isSync, soArc<Mutex<T>>isSend.Arcshares ownership,Mutexrestores exclusivity: total 4000, no lost write.
L’erreur : un compteur partagé avec Cell
On veut un compteur que plusieurs threads incrémentent. Arc pour le partager, Cell pour le modifier à travers une référence partagée : sur le papier, tout y est.
use std::cell::Cell;
use std::sync::Arc;
use std::thread;
fn main() {
let total = Arc::new(Cell::new(0));
let copie = Arc::clone(&total);
let h = thread::spawn(move || {
copie.set(copie.get() + 1);
});
h.join().unwrap();
}error[E0277]: `Cell<i32>` cannot be shared between threads safely
--> arc_cell.rs:8:27
|
8 | let h = thread::spawn(move || {
| _____________-------------_^
| | |
| | required by a bound introduced by this call
9 | | copie.set(copie.get() + 1);
10 | | });
| |_____^ `Cell<i32>` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `Cell<i32>`
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead
= note: required for `Arc<Cell<i32>>` to implement `Send`Trois lignes à lire dans l’ordre inverse. spawn exige une closure Send. La closure contient un Arc<Cell<i32>>, qui devrait donc être Send. Et il ne l’est pas, parce que Cell<i32> n’est pas Sync.
Le danger est concret. copie.set(copie.get() + 1) fait trois choses : lire, ajouter, écrire. Deux threads qui le font en même temps peuvent lire tous les deux 0 et écrire tous les deux 1. Un ajout est perdu, sans erreur ni panic. C’est une course aux données, et rustc la refuse avant qu’elle existe.
Send et Sync : deux questions différentes
Send : la valeur change de thread Sync : la valeur reste, on la partage
thread A thread B thread A thread B
┌───────┐ ┌───────┐ ┌───────┐
│ T │ ────▶ │ T │ │ T │ ◀──── &T
└───────┘ └───────┘ └───────┘
n'y a plus seul ▲
accès propriétaire └──── &T (A lit aussi)Send: on peut déplacer la valeur dans un autre thread. Presque tout estSend. L’exception connue estRc, dont le compteur n’est pas atomique.Sync: plusieurs threads peuvent y accéder en même temps à travers un&. La définition exacte tient en une ligne :TestSyncsi&TestSend.
Ce sont des traits marqueurs : aucune méthode, rien à écrire. Le compilateur les déduit de la composition du type. Une struct dont tous les champs sont Send est Send.
Chaque case de ce tableau a été vérifiée en compilant fn exige<T: Send>() {} (ou Sync) avec rustc 1.100 :
| Type | Send | Sync | Pourquoi |
|---|---|---|---|
i32, String, Vec<i32> | oui | oui | aucune mutation à travers un & |
Rc<i32> | non | non | compteur non atomique |
Arc<i32>, Arc<Vec<i32>> | oui | oui | compteur atomique, contenu en lecture seule |
Cell<i32>, RefCell<i32> | oui | non | mutation à travers un &, sans protection |
Arc<Cell<i32>> | non | non | Arc<T> exige T: Sync |
Mutex<i32>, AtomicU32 | oui | oui | mutation à travers un &, synchronisée |
Arc<Mutex<i32>> | oui | oui | les deux réunis |
MutexGuard<i32> | non | oui | doit être rendu par le thread qui a pris le verrou |
*const i32 | non | non | pointeur brut : aucune garantie |
La ligne Cell explique l’erreur du début. Une Cell est Send : la déplacer dans un thread est permis, et ce programme affiche join : Ok(1) :
let c = Cell::new(0);
let h = thread::spawn(move || {
c.set(c.get() + 1);
c.get()
});
println!("join : {:?}", h.join());Un seul thread y accède à la fois, donc rien ne peut mal tourner. Ce qui est interdit, c’est le partage. Et un Arc est précisément un outil de partage : chaque clone donne accès à la même valeur. Voilà pourquoi Arc<T> n’est Send que si T est Sync.
Arc seul : partagé, donc en lecture seule
Retirons la Cell. Un Arc<Vec<i32>> passe d’un thread à l’autre sans difficulté. Mais essayons d’y écrire :
let v = Arc::new(vec![1, 2, 3]);
let copie = Arc::clone(&v);
let h = thread::spawn(move || {
copie.push(4);
});error[E0596]: cannot borrow data in an `Arc` as mutable
--> arc_push.rs:8:9
|
8 | copie.push(4);
| ^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Arc<Vec<i32>>`Ce n’est plus une question de thread. C’est la règle de l’emprunt : modifier demande un accès exclusif, et un Arc existe pour qu’il y ait plusieurs propriétaires. Il ne peut donc donner que des &.
On est coincé entre deux refus :
Arc<Vec<i32>> partage : oui modifier : non (E0596)
Arc<Cell<i32>> modifier : oui partage : non (E0277)
Arc<Mutex<i32>> partage : oui modifier : oui, un thread à la foisMutex : l’exclusivité, vérifiée à l’exécution
Un Mutex<T> enferme une valeur derrière un verrou. Pour y toucher, il faut appeler lock(), qui attend que le verrou soit libre et rend un garde, le MutexGuard :
let total = Mutex::new(0);
let garde = total.lock().unwrap();
println!("verrou pris : try_lock = {}", total.try_lock().is_ok());
drop(garde);
println!("verrou rendu : try_lock = {}", total.try_lock().is_ok());
{
let mut g = total.lock().unwrap();
*g += 1;
}
println!("total : {:?}", total.lock().unwrap());verrou pris : try_lock = false
verrou rendu : try_lock = true
total : 1Deux choses à retenir. Le garde se comporte comme un &mut T : on écrit *g += 1. Et il n’y a pas de unlock() : le verrou est rendu quand le garde est détruit, à la fin du bloc ou par drop. Impossible d’oublier de le rendre, et impossible de toucher à la valeur sans l’avoir pris, puisque la valeur est dans le Mutex.
C’est le même marché que RefCell : la règle « un seul écrivain » est vérifiée à l’exécution plutôt qu’à la compilation. La différence est dans la réaction. Une RefCell déjà empruntée panique. Un Mutex déjà pris fait attendre.
Avec Arc autour, le compteur du début fonctionne :
let total = Arc::new(Mutex::new(0));
let mut poignees = Vec::new();
for _ in 0..4 {
let copie = Arc::clone(&total);
poignees.push(thread::spawn(move || {
for _ in 0..1000 {
*copie.lock().unwrap() += 1;
}
}));
}
for h in poignees {
h.join().unwrap();
}
println!("total : {}", total.lock().unwrap());
println!("propriétaires : {}", Arc::strong_count(&total));total : 4000
propriétaires : 1Quatre threads, mille ajouts chacun, aucun perdu. Dans le temps, cela ressemble à ceci :
temps ──────────────────────────────────────────────▶
thread 1 ── lock() ████ garde ████ drop
thread 2 ────── lock() ░░ attend ░░ ████ garde ████ drop
▲
└─ le verrou change de mainChacun son rôle. Arc répond à « qui possède la donnée » : tout le monde, jusqu’au dernier clone. Mutex répond à « qui a le droit d’y écrire maintenant » : celui qui tient le garde.
Ce que le Mutex ne règle pas
Le verrou empoisonné. Pourquoi lock() rend-il un Result ? Parce qu’un thread peut paniquer en tenant le verrou, et laisser la valeur à moitié modifiée :
let h = thread::spawn(move || {
let mut g = copie.lock().unwrap();
*g += 1;
panic!("le thread s'arrête avec le verrou en main");
});
println!("join : erreur ? {}", h.join().is_err());
match total.lock() {
Ok(g) => println!("valeur : {}", *g),
Err(e) => println!("verrou empoisonné, valeur : {}", *e.into_inner()),
}thread '<unnamed>' (537390) panicked at poison.rs:10:9:
le thread s'arrête avec le verrou en main
join : erreur ? true
verrou empoisonné, valeur : 1Le verrou est bien rendu (le garde est détruit pendant le panic), mais le Mutex est marqué. Le .unwrap() habituel propage alors le panic aux autres threads. Quand la valeur reste cohérente, into_inner() la récupère.
L’interblocage. Deux verrous, deux threads, pris dans l’ordre inverse :
thread::spawn(move || {
let _ga = a1.lock().unwrap();
thread::sleep(Duration::from_millis(50));
let _gb = b1.lock().unwrap();
tx1.send("thread 1").unwrap();
});
thread::spawn(move || {
let _gb = b.lock().unwrap();
thread::sleep(Duration::from_millis(50));
let _ga = a.lock().unwrap();
tx.send("thread 2").unwrap();
});
match rx.recv_timeout(Duration::from_millis(500)) {
Ok(nom) => println!("{nom} a terminé"),
Err(_) => println!("aucun thread n'a terminé après 500 ms : interblocage"),
}aucun thread n'a terminé après 500 ms : interblocage thread 1 tient a ████████████████▶ attend b ░░░░░░░░▶
thread 2 tient b ████████████████▶ attend a ░░░░░░░░▶
chacun attend le verrou que l'autre ne rendra jamaisCe programme compile sans erreur ni avertissement. Aucune règle de possession n’est violée : chaque accès est exclusif. Rust empêche la course aux données, pas l’interblocage. Le remède est une convention : prendre les verrous toujours dans le même ordre, et les tenir le moins longtemps possible.
Ce que l’image cache
- Pour un simple compteur, un type atomique suffit.
Arc<AtomicU32>avecfetch_add(1, Ordering::Relaxed)donne le mêmetotal : 4000, sans verrou ni garde. Mesuré :AtomicU32fait 4 octets,Mutex<u32>en fait 16. RwLockdistingue lecteurs et écrivain. Plusieursread()en même temps, ou un seulwrite(). Vérifié : avec deux lecteurs actifs,try_write()échoue. C’est la règle de l’emprunt, à l’exécution et entre threads.Mutexne rend pas tout partageable.Arc<Mutex<Rc<i32>>>est refusé (E0277, «Rc<i32>cannot be sent between threads safely ») :Mutex<T>n’estSyncque siTestSend, puisque le verrou donne la valeur tour à tour à chaque thread.- Le garde ne change pas de thread.
MutexGuardn’est pasSend: le verrou doit être rendu par le thread qui l’a pris. Le déplacer dans un autre thread est refusé à la compilation. thread::scopene change rien àSync. Emprunter une&Celldepuis un thread scopé donne la même erreur : une&Celln’est pasSend, précisément parce queCelln’est pasSync.- Tenir le garde trop longtemps coûte cher.
let g = m.lock().unwrap();garde le verrou jusqu’à la fin du bloc.*m.lock().unwrap() += 1;le rend à la fin de l’instruction. unsafe impl Sendexiste. C’est ainsi queArcetMutexsont eux-mêmes déclarés dans la bibliothèque standard. L’écrire soi-même, c’est promettre au compilateur ce qu’il ne peut plus vérifier.
Pour aller plus loin
- Volume 7, numéro 02 de The Rust Loop, « Send, Sync &
Arc<Mutex<T>>», qui détaille le partage entre threads et la limite de la garantie : pas de data race, mais pas de protection contre l’interblocage (lien en bas de page). - Articles précédents : le move (E0382), l’emprunt (E0502), les slices, les lifetimes (E0106), l’élision,
'static, enums et match (E0004), Option et unwrap, newtype et type-state (E0599), Result et?(E0277), thiserror et anyhow (E0119), panic et invariants, traits et generics (E0369), dyn et vtable (E0038), règle de l’orphelin (E0117), Box et types récursifs (E0072), Rc et Arc (E0277), Cell et RefCell, threads et move (E0373). - The Rust Book : la concurrence à état partagé et les traits
SendetSync - La bibliothèque standard :
Send,SyncetMutex - Le Rustonomicon : Send et Sync
The error: a counter shared with Cell
We want a counter that several threads increment. Arc to share it, Cell to mutate it through a shared reference: on paper, it’s all there.
use std::cell::Cell;
use std::sync::Arc;
use std::thread;
fn main() {
let total = Arc::new(Cell::new(0));
let copie = Arc::clone(&total);
let h = thread::spawn(move || {
copie.set(copie.get() + 1);
});
h.join().unwrap();
}error[E0277]: `Cell<i32>` cannot be shared between threads safely
--> arc_cell.rs:8:27
|
8 | let h = thread::spawn(move || {
| _____________-------------_^
| | |
| | required by a bound introduced by this call
9 | | copie.set(copie.get() + 1);
10 | | });
| |_____^ `Cell<i32>` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `Cell<i32>`
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead
= note: required for `Arc<Cell<i32>>` to implement `Send`Three lines to read in reverse order. spawn requires a Send closure. The closure contains an Arc<Cell<i32>>, which should therefore be Send. And it isn’t, because Cell<i32> is not Sync.
The danger is concrete. copie.set(copie.get() + 1) does three things: read, add, write. Two threads doing it at the same time can both read 0 and both write 1. One addition is lost, with no error and no panic. That’s a data race, and rustc refuses it before it exists.
Send and Sync: two different questions
Send: the value changes threads Sync: the value stays, it is shared
thread A thread B thread A thread B
┌───────┐ ┌───────┐ ┌───────┐
│ T │ ────▶ │ T │ │ T │ ◀──── &T
└───────┘ └───────┘ └───────┘
no longer sole ▲
has access owner └──── &T (A reads too)Send: the value can be moved into another thread. Almost everything isSend. The well-known exception isRc, whose counter isn’t atomic.Sync: several threads can access it at the same time through a&. The exact definition fits in one line:TisSyncif&TisSend.
They are marker traits: no method, nothing to write. The compiler derives them from what the type is made of. A struct whose fields are all Send is Send.
Every cell of this table was checked by compiling fn exige<T: Send>() {} (or Sync) with rustc 1.100:
| Type | Send | Sync | Why |
|---|---|---|---|
i32, String, Vec<i32> | yes | yes | no mutation through a & |
Rc<i32> | no | no | non-atomic counter |
Arc<i32>, Arc<Vec<i32>> | yes | yes | atomic counter, read-only content |
Cell<i32>, RefCell<i32> | yes | no | mutation through a &, unprotected |
Arc<Cell<i32>> | no | no | Arc<T> requires T: Sync |
Mutex<i32>, AtomicU32 | yes | yes | mutation through a &, synchronized |
Arc<Mutex<i32>> | yes | yes | both combined |
MutexGuard<i32> | no | yes | must be released by the thread that took the lock |
*const i32 | no | no | raw pointer: no guarantee |
The Cell row explains the opening error. A Cell is Send: moving it into a thread is allowed, and this program prints join : Ok(1):
let c = Cell::new(0);
let h = thread::spawn(move || {
c.set(c.get() + 1);
c.get()
});
println!("join : {:?}", h.join());Only one thread accesses it at a time, so nothing can go wrong. What is forbidden is sharing. And an Arc is precisely a sharing tool: every clone gives access to the same value. That’s why Arc<T> is only Send if T is Sync.
Arc alone: shared, hence read-only
Let’s remove the Cell. An Arc<Vec<i32>> goes from one thread to another without trouble. But let’s try to write to it:
let v = Arc::new(vec![1, 2, 3]);
let copie = Arc::clone(&v);
let h = thread::spawn(move || {
copie.push(4);
});error[E0596]: cannot borrow data in an `Arc` as mutable
--> arc_push.rs:8:9
|
8 | copie.push(4);
| ^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Arc<Vec<i32>>`This is no longer about threads. It’s the borrowing rule: mutating requires exclusive access, and an Arc exists so that there are several owners. So it can only hand out &.
We’re stuck between two refusals:
Arc<Vec<i32>> share: yes mutate: no (E0596)
Arc<Cell<i32>> mutate: yes share: no (E0277)
Arc<Mutex<i32>> share: yes mutate: yes, one thread at a timeMutex: exclusivity, checked at run time
A Mutex<T> locks a value away. To touch it, you must call lock(), which waits for the lock to be free and returns a guard, the MutexGuard:
let total = Mutex::new(0);
let garde = total.lock().unwrap();
println!("verrou pris : try_lock = {}", total.try_lock().is_ok());
drop(garde);
println!("verrou rendu : try_lock = {}", total.try_lock().is_ok());
{
let mut g = total.lock().unwrap();
*g += 1;
}
println!("total : {:?}", total.lock().unwrap());verrou pris : try_lock = false
verrou rendu : try_lock = true
total : 1Two things to remember. The guard behaves like a &mut T: you write *g += 1. And there is no unlock(): the lock is released when the guard is destroyed, at the end of the block or through drop. You can’t forget to release it, and you can’t touch the value without taking it, since the value is inside the Mutex.
It’s the same deal as RefCell: the “single writer” rule is checked at run time instead of compile time. The difference is in the reaction. A RefCell that is already borrowed panics. A Mutex that is already taken makes you wait.
With Arc around it, the opening counter works:
let total = Arc::new(Mutex::new(0));
let mut poignees = Vec::new();
for _ in 0..4 {
let copie = Arc::clone(&total);
poignees.push(thread::spawn(move || {
for _ in 0..1000 {
*copie.lock().unwrap() += 1;
}
}));
}
for h in poignees {
h.join().unwrap();
}
println!("total : {}", total.lock().unwrap());
println!("propriétaires : {}", Arc::strong_count(&total));total : 4000
propriétaires : 1Four threads, a thousand additions each, none lost. Over time, it looks like this:
time ───────────────────────────────────────────────▶
thread 1 ── lock() ████ guard ████ drop
thread 2 ────── lock() ░░ waits ░░░ ████ guard ████ drop
▲
└─ the lock changes handsEach has its role. Arc answers “who owns the data”: everyone, until the last clone. Mutex answers “who may write to it right now”: whoever holds the guard.
What Mutex doesn’t solve
The poisoned lock. Why does lock() return a Result? Because a thread can panic while holding the lock, and leave the value half-modified:
let h = thread::spawn(move || {
let mut g = copie.lock().unwrap();
*g += 1;
panic!("le thread s'arrête avec le verrou en main");
});
println!("join : erreur ? {}", h.join().is_err());
match total.lock() {
Ok(g) => println!("valeur : {}", *g),
Err(e) => println!("verrou empoisonné, valeur : {}", *e.into_inner()),
}thread '<unnamed>' (537390) panicked at poison.rs:10:9:
le thread s'arrête avec le verrou en main
join : erreur ? true
verrou empoisonné, valeur : 1The lock is indeed released (the guard is destroyed during the panic), but the Mutex is marked. The usual .unwrap() then propagates the panic to the other threads. When the value is still consistent, into_inner() gets it back.
The deadlock. Two locks, two threads, taken in opposite order:
thread::spawn(move || {
let _ga = a1.lock().unwrap();
thread::sleep(Duration::from_millis(50));
let _gb = b1.lock().unwrap();
tx1.send("thread 1").unwrap();
});
thread::spawn(move || {
let _gb = b.lock().unwrap();
thread::sleep(Duration::from_millis(50));
let _ga = a.lock().unwrap();
tx.send("thread 2").unwrap();
});
match rx.recv_timeout(Duration::from_millis(500)) {
Ok(nom) => println!("{nom} a terminé"),
Err(_) => println!("aucun thread n'a terminé après 500 ms : interblocage"),
}aucun thread n'a terminé après 500 ms : interblocage thread 1 holds a ████████████████▶ wants b ░░░░░░░░░▶
thread 2 holds b ████████████████▶ wants a ░░░░░░░░░▶
each waits for the lock the other will never releaseThis program compiles with no error and no warning. No ownership rule is broken: every access is exclusive. Rust prevents the data race, not the deadlock. The cure is a convention: always take locks in the same order, and hold them for as short a time as possible.
What the picture hides
- For a plain counter, an atomic type is enough.
Arc<AtomicU32>withfetch_add(1, Ordering::Relaxed)gives the sametotal : 4000, with no lock and no guard. Measured:AtomicU32is 4 bytes,Mutex<u32>is 16. RwLocktells readers from the writer. Severalread()at once, or a singlewrite(). Checked: with two active readers,try_write()fails. It’s the borrowing rule, at run time and across threads.Mutexdoesn’t make everything shareable.Arc<Mutex<Rc<i32>>>is refused (E0277, “Rc<i32>cannot be sent between threads safely”):Mutex<T>is onlySyncifTisSend, since the lock hands the value to each thread in turn.- The guard doesn’t change threads.
MutexGuardis notSend: the lock must be released by the thread that took it. Moving it into another thread is refused at compile time. thread::scopechanges nothing aboutSync. Borrowing a&Cellfrom a scoped thread gives the same error: a&Cellis notSend, precisely becauseCellis notSync.- Holding the guard too long is expensive.
let g = m.lock().unwrap();keeps the lock until the end of the block.*m.lock().unwrap() += 1;releases it at the end of the statement. unsafe impl Sendexists. That’s howArcandMutexthemselves are declared in the standard library. Writing it yourself means promising the compiler what it can no longer check.
Going further
- Volume 7, issue 02 of The Rust Loop, “Send, Sync &
Arc<Mutex<T>>”, which details sharing between threads and the limit of the guarantee: no data race, but no protection against deadlock (link at the bottom of the page). - Previous articles: move (E0382), borrowing (E0502), slices, lifetimes (E0106), elision,
'static, enums and match (E0004), Option and unwrap, newtype and type-state (E0599), Result and?(E0277), thiserror and anyhow (E0119), panic and invariants, traits and generics (E0369), dyn and the vtable (E0038), the orphan rule (E0117), Box and recursive types (E0072), Rc and Arc (E0277), Cell and RefCell, threads and move (E0373). - The Rust Book: shared-state concurrency and the
SendandSynctraits - The standard library:
Send,SyncandMutex - The Rustonomicon: Send and Sync