90: Move "last_state = state" assignment r=adamgreig a=adamgreen
I believe that I have found a bug in the samples found in the concurrency chapter where the value of the `last_state` variable should be updated on each loop iteration but it is only updated on the detection of the first leading edge. For example:
```rust
loop {
let state = read_signal_level();
if state && !last_state {
last_state = state;
// DANGER - Not actually safe! Could cause data races.
unsafe { COUNTER += 1 };
}
}
```
I think that loop should actually be written as:
```rust
loop {
let state = read_signal_level();
if state && !last_state {
// DANGER - Not actually safe! Could cause data races.
unsafe { COUNTER += 1 };
}
last_state = state;
}
```
As the code exists today, I think it would detect the first leading edge, set last_state to true and then never be updated again which would also mean that it never detects another leading edge.
Co-authored-by: Adam Green <adamgreen@users.noreply.github.com>
[Work in Progress] - The Embedded Rust Book
Documentation on how to use the Rust Programming Language to develop firmware for bare metal (microcontroller) devices
This project is developed and maintained by the Resources team.
See the issue tracker for more details. This is a very early work in progress.
Online Copies of this Book
This book is located at https://docs.rust-embedded.org/book/
License
The Embedded Rust Book (this project) is distributed under the following licenses:
- The code samples and free-standing Cargo projects contained within this book are licensed under the terms of both the MIT License and the Apache License v2.0.
- The written prose contained within this book is licensed under the terms of the Creative Commons CC-BY-SA v4.0 license.
Copies of the licenses used by this project may also be found here:
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.
Code of Conduct
Contribution to this crate is organized under the terms of the Rust Code of Conduct, the maintainer of this crate, the Resources team, promises to intervene to uphold that code of conduct.