Skip to content

Commit 78c92cd

Browse files
Merge #245
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>
2 parents 5555a97 + a8e37ae commit 78c92cd

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/concurrency/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ you can get away with such a simple approach this can be a great solution.
4242

4343
Unlike non-embedded Rust, we will not usually have the luxury of creating
4444
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
4646
know how to access whatever shared memory we are using. At the lowest level,
4747
this means we must have _statically allocated_ mutable memory, which
4848
both the interrupt handler and the main code can refer to.
@@ -124,7 +124,7 @@ fn timer() {
124124
}
125125
```
126126

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
128128
have similar mechanisms for executing code in a critical section. This is also
129129
the same as disabling interrupts, running some code, and then re-enabling
130130
interrupts.
@@ -138,7 +138,7 @@ for two reasons:
138138
If `COUNTER` was being shared by multiple interrupt handlers that might
139139
_preempt_ each other, then each one might require a critical section as well.
140140

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.
142142

143143
It's worth noting that while a critical section guarantees no interrupts will
144144
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
209209
can do better in Rust!
210210

211211
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
213213
counter, but you could do something very similar with atomics.
214214

215215
```rust,ignore
@@ -274,7 +274,7 @@ fn timer() {
274274
We've moved our `unsafe` code to inside our carefully-planned abstraction,
275275
and now our application code does not contain any `unsafe` blocks.
276276

277-
This design requires the application pass a `CriticalSection` token in:
277+
This design requires that the application pass a `CriticalSection` token in:
278278
these tokens are only safely generated by `interrupt::free`, so by requiring
279279
one be passed in, we ensure we are operating inside a critical section, without
280280
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.
302302
To tell the compiler we have taken care that the `CSCounter` is in fact safe
303303
to share between threads, we implement the Sync trait explicitly. As with the
304304
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.
306306

307307
## Mutexes
308308

@@ -383,8 +383,8 @@ to get a safe counter with no unsafe code at all!
383383

384384
This is great for simple types like the `u32` of our counter, but what about
385385
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`.
388388

389389
## Sharing Peripherals
390390

@@ -499,7 +499,7 @@ interrupt::free(|cs| {
499499
});
500500
```
501501

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
503503
prevents the interrupt firing as usual, and lets us borrow the mutex. The
504504
`RefCell` then gives us an `&Option<GPIOA>`, and tracks how long it remains
505505
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
509509
an `&Option<&GPIOA>` with `as_ref()`, which we can finally `unwrap()` to obtain
510510
the `&GPIOA` which lets us modify the peripheral.
511511

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`
513513
should be used instead. The following code shows an example using the TIM2 timer.
514514

515515
```rust,ignore
@@ -587,7 +587,7 @@ primitives, and often interoperate with hardware features such as DMA engines.
587587
[FreeRTOS]: https://freertos.org/
588588
[ChibiOS]: http://chibios.org/
589589

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,
591591
but it's an interesting area so watch this space!
592592

593593
## Multiple Cores

0 commit comments

Comments
 (0)