@@ -250,11 +250,13 @@ access to memory.
250
250
251
251
### Atomics
252
252
253
- Accessing atomics stored in `static ` variables is memory safe . If you are
253
+ Accessing [ atomic types ] stored in `static ` variables is memory safe . If you are
254
254
building abstractions like channels on top of them (which likely will require
255
255
`unsafe ` code to access some shared buffer ) make sure you use the right
256
256
`Ordering ` or your abstraction will be unsound.
257
257
258
+ [atomic types]: https: // doc.rust-lang.org/core/sync/atomic/index.html
259
+
258
260
Here 's an example of using a static variable for synchronization (a delay in
259
261
this case).
260
262
@@ -480,6 +482,13 @@ bound is required for this pattern.
480
482
We can abstract the "disable all interrupts" critical section pattern into a
481
483
` Mutex ` type.
482
484
485
+ > Aside: "MutEx" stands for Mutual Exclusion and it's a synchronization
486
+ > mechanism that ensures that execution contexts (threads or interrupt handlers)
487
+ > get access to a single memory location in a "mutually exclusive" fashion.
488
+ > Meaning that at any point in time at most one execution context gets exclusive
489
+ > access over the memory location; only the execution context with exclusive
490
+ > access can read / write to said memory location.
491
+
483
492
``` rust
484
493
{{#include .. / ci / concurrency / examples / mutex . rs}}```
485
494
@@ -696,6 +705,16 @@ instructions are inserted where appropriate. If you are using the correct
696
705
sections based on atomics, AKA spinlocks, are memory safe to use on multi-core
697
706
devices though they can deadlock.
698
707
708
+ > Aside: an spinlock is a Mutual Exclusion mechanism that uses an atomic
709
+ > variable to synchronize access to a memory location. While an execution
710
+ > context has exclusive access over the memory location, any other execution
711
+ > context that attempts to access the memory location will continuously check
712
+ > the state of the atomic variable in a loop ("spin") until it indicates that
713
+ > the shared memory location is free to access. It's probably easiest to look at
714
+ > the [ implementation] of a spinlock to understand how it works.
715
+
716
+ [ implementation ] : https://docs.rs/spin/0.5.0/src/spin/mutex.rs.html#129-164
717
+
699
718
``` rust
700
719
// spin = "0.5.0"
701
720
use spin :: Mutex ;
0 commit comments