Skip to content

Latest commit

 

History

History
61 lines (38 loc) · 2.36 KB

File metadata and controls

61 lines (38 loc) · 2.36 KB

Step 1.8: Thread safety

Rust has Send and Sync marker traits which are fundamental for concurrency and thread safety story in Rust and represent one of fearless concurrency corner stones (which allow to avoid data races at compile time).

For better understanding Send/Sync purpose, design, limitations and use cases, read through the following articles:

Task

Estimated time: 1 day

Implement the following types, which meet conditions:

  1. OnlySync is Sync, but !Send.
  2. OnlySend is Send, but !Sync.
  3. SyncAndSend is both Sync and Send.
  4. NotSyncNotSend is both !Sync and !Send.

All inner details of implementation are on your choice.

Play with these types from multiple threads to see how compile time fearless concurrency works in practice.

Questions

After completing everything above, you should be able to answer (and understand why) the following questions:

  • What does "fearless concurrency" mean in Rust? With which mechanisms does Rust fulfill this guarantee exactly?
  • Why do Send and Sync exist at all? How is it related to interior mutability?