You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
245: Fix Typos and Improve Readability r=adamgreig a=lonesometraveler
First, I want to thank you all for this great resource. I am learning a lot from it.
I found some typos while reading it for a second time. This PR fixes typos in concurrency/index.md.
Co-authored-by: KENTARO OKUDA <lonesometraveler@mac.com>
Co-authored-by: lonesometraveler <lonesometraveler@mac.com>
Copy file name to clipboardExpand all lines: src/concurrency/index.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ you can get away with such a simple approach this can be a great solution.
42
42
43
43
Unlike non-embedded Rust, we will not usually have the luxury of creating
44
44
heap allocations and passing references to that data into a newly-created
45
-
thread. Instead our interrupt handlers might be called at any time and must
45
+
thread. Instead, our interrupt handlers might be called at any time and must
46
46
know how to access whatever shared memory we are using. At the lowest level,
47
47
this means we must have _statically allocated_ mutable memory, which
48
48
both the interrupt handler and the main code can refer to.
@@ -124,7 +124,7 @@ fn timer() {
124
124
}
125
125
```
126
126
127
-
In this example we use `cortex_m::interrupt::free`, but other platforms will
127
+
In this example, we use `cortex_m::interrupt::free`, but other platforms will
128
128
have similar mechanisms for executing code in a critical section. This is also
129
129
the same as disabling interrupts, running some code, and then re-enabling
130
130
interrupts.
@@ -138,7 +138,7 @@ for two reasons:
138
138
If `COUNTER` was being shared by multiple interrupt handlers that might
139
139
_preempt_ each other, then each one might require a critical section as well.
140
140
141
-
This solves our immediate problem, but we're still left writing a lot of unsafe code which we need to carefully reason about, and we might be using critical sections needlessly. Since each critical section temporarily pauses interrupt processing, there is an associated cost of some extra code size and higher interrupt latency and jitter (interrupts may take longer to be processed, and the time until they are processed will be more variable). Whether this is a problem depends on your system, but in general we'd like to avoid it.
141
+
This solves our immediate problem, but we're still left writing a lot of unsafe code which we need to carefully reason about, and we might be using critical sections needlessly. Since each critical section temporarily pauses interrupt processing, there is an associated cost of some extra code size and higher interrupt latency and jitter (interrupts may take longer to be processed, and the time until they are processed will be more variable). Whether this is a problem depends on your system, but in general, we'd like to avoid it.
142
142
143
143
It's worth noting that while a critical section guarantees no interrupts will
144
144
fire, it does not provide an exclusivity guarantee on multi-core systems! The
@@ -209,7 +209,7 @@ blocks which must be very carefully checked and are not ergonomic. Surely we
209
209
can do better in Rust!
210
210
211
211
We can abstract our counter into a safe interface which can be safely used
212
-
anywhere else in our code. For this example we'll use the critical-section
212
+
anywhere else in our code. For this example, we'll use the critical-section
213
213
counter, but you could do something very similar with atomics.
214
214
215
215
```rust,ignore
@@ -274,7 +274,7 @@ fn timer() {
274
274
We've moved our `unsafe` code to inside our carefully-planned abstraction,
275
275
and now our application code does not contain any `unsafe` blocks.
276
276
277
-
This design requires the application pass a `CriticalSection` token in:
277
+
This design requires that the application pass a `CriticalSection` token in:
278
278
these tokens are only safely generated by `interrupt::free`, so by requiring
279
279
one be passed in, we ensure we are operating inside a critical section, without
280
280
having to actually do the lock ourselves. This guarantee is provided statically
@@ -302,7 +302,7 @@ variables _must_ be Sync, since they can be accessed by multiple threads.
302
302
To tell the compiler we have taken care that the `CSCounter` is in fact safe
303
303
to share between threads, we implement the Sync trait explicitly. As with the
304
304
previous use of critical sections, this is only safe on single-core platforms:
305
-
with multiple cores you would need to go to greater lengths to ensure safety.
305
+
with multiple cores, you would need to go to greater lengths to ensure safety.
306
306
307
307
## Mutexes
308
308
@@ -383,8 +383,8 @@ to get a safe counter with no unsafe code at all!
383
383
384
384
This is great for simple types like the `u32` of our counter, but what about
385
385
more complex types which are not Copy? An extremely common example in an
386
-
embedded context is a peripheral struct, which generally are not Copy.
387
-
For that we can turn to `RefCell`.
386
+
embedded context is a peripheral struct, which generally is not Copy.
387
+
For that, we can turn to `RefCell`.
388
388
389
389
## Sharing Peripherals
390
390
@@ -499,7 +499,7 @@ interrupt::free(|cs| {
499
499
});
500
500
```
501
501
502
-
Finally we use `MY_GPIO` in a safe and concurrent fashion. The critical section
502
+
Finally, we use `MY_GPIO` in a safe and concurrent fashion. The critical section
503
503
prevents the interrupt firing as usual, and lets us borrow the mutex. The
504
504
`RefCell` then gives us an `&Option<GPIOA>`, and tracks how long it remains
505
505
borrowed - once that reference goes out of scope, the `RefCell` will be updated
@@ -509,7 +509,7 @@ Since we can't move the `GPIOA` out of the `&Option`, we need to convert it to
509
509
an `&Option<&GPIOA>` with `as_ref()`, which we can finally `unwrap()` to obtain
510
510
the `&GPIOA` which lets us modify the peripheral.
511
511
512
-
If we need a mutable references to shared resources, then `borrow_mut` and `deref_mut`
512
+
If we need a mutable reference to a shared resource, then `borrow_mut` and `deref_mut`
513
513
should be used instead. The following code shows an example using the TIM2 timer.
514
514
515
515
```rust,ignore
@@ -587,7 +587,7 @@ primitives, and often interoperate with hardware features such as DMA engines.
587
587
[FreeRTOS]: https://freertos.org/
588
588
[ChibiOS]: http://chibios.org/
589
589
590
-
At the time of writing there are not many Rust RTOS examples to point to,
590
+
At the time of writing, there are not many Rust RTOS examples to point to,
0 commit comments