Added Bonus Section implementing a proper Parker

The problems addressed in the earlier version led to an "incorrect"
example which is bad to pass along after reading a whole book. after
getting some feedback in #2 i decided to show how we can create a
proper `Parker`.

The main example (which I assume most interested readers will copy) now
uses a proper parking thechnique so there should be no more dataraces
left.

I also removed the "Reader Excercise" paragraph suggesting that they
explore a way to implement proper parking since we now show that in
our main example.
This commit is contained in:
Carl Fredrik Samson
2020-04-13 14:16:32 +02:00
parent f4b2029788
commit d9eb756ef7
10 changed files with 441 additions and 240 deletions

View File

@@ -47,6 +47,11 @@ Feedback, questions or discussion is welcome in the issue tracker.
readability and make it easier to reason about. In addition I fixed a mistake
in the `Poll` method and a possible race condition. See #2 for more details.
**2020-04-13:** Added a "bonus section" to the [Implementing Futures chapter](https://cfsamson.github.io/books-futures-explained/6_future_example.html) where we avoid using `thread::park` and instead show how we
can use a `Condvar` and a `Mutex` to create a proper `Parker`. Updated the [Finished Example](https://cfsamson.github.io/books-futures-explained/8_finished_example.html) to reflect these changes. Unfortunately, this led us
a few lines over my initial promis of keeping the example below 200 LOC but the I think the inclusion
is worth it.
## License
This book is MIT licensed.