例
Send + Sync
見かけるほとんどの型はSend + Syncです:
i8、f32、bool、char、&strなど(T1, T2)、[T; N]、&[T]、struct { x: T }などString、Option<T>、Vec<T>、Box<T>などArc<T>: アトミック参照カウントにより、明示的にスレッドセーフ。Mutex<T>: 内部ロックにより明示的にスレッドセーフ。mpsc::Sender<T>: As of 1.72.0.AtomicBool,AtomicU8, …: 特別なアトミック命令を利用。
ジェネリクスは、型パラメタがSend + Syncであるとき、通常はSend + Syncです。
Send + !Sync
これらの型は別のスレッドにムーブすることができますが、このようなムーブはスレッドセーフではありません。通常は内部可変性がその原因です:
mpsc::Receiver<T>Cell<T>RefCell<T>
!Send + Sync
These types are safe to access (via shared references) from multiple threads, but they cannot be moved to another thread:
MutexGuard<T: Sync>: Uses OS level primitives which must be deallocated on the thread which created them. However, an already-locked mutex can have its guarded variable read by any thread with which the guard is shared.
!Send + !Sync
このような型はスレッドセーフではないため、別のスレッドにムーブすることはできません:
Rc<T>: それぞれのRc<T>はRcBox<T>への参照を持っています。これは、アトミックでない参照カウントを持っています。*const T,*mut T: Rust は、生ポインターは同時実行性に関する特別な考慮事項がある可能性があることを仮定しています。