Skip to content

Commit

Permalink
Update Concurrency course with times (#2007)
Browse files Browse the repository at this point in the history
As I mentioned in #1536:

* Break into segments at approximately the places @fw-immunant put
breaks
 * Move all of the files into `src/concurrency`
 * Add timings and segment/session metadata so course outlines appear

There's room for more work here, including some additional feedback from
@fw-immunant after the session I observed, but let's do one step at a
time :)
  • Loading branch information
djmitche committed Apr 23, 2024
1 parent a03b7e6 commit face5af
Show file tree
Hide file tree
Showing 58 changed files with 385 additions and 246 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ members = [
"src/borrowing",
"src/control-flow-basics",
"src/error-handling",
"src/exercises",
"src/exercises/concurrency/chat-async",
"src/concurrency/sync-exercises",
"src/concurrency/async-exercises/chat-async",
"src/generics",
"src/iterators",
"src/lifetimes",
Expand Down
62 changes: 45 additions & 17 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,26 @@ use-boolean-and = true
#
# Please keep the table sorted and avoid multi-step redirects.
[output.html.redirect]
"tuples-and-arrays/tuples-and-arrays.html" = "tuples.html"
"async/async-await.html" = "../concurrency/async/async-await.html"
"async/channels.html" = "../concurrency/async-control-flow/channels.html"
"async/concurrency/channels.html" = "../channels.html"
"async/pitfall/async-traits.html" = "../pitfalls/async-traits.html"
"basic-syntax.html" = "control-flow-basics.html"
"async/control-flow/join.html" = "../concurrency/async-control-flow/join.html"
"async/control-flow/select.html" = "../concurrency/async-control-flow/select.html"
"async/futures.html" = "../concurrency/async/futures.html"
"async.html" = "concurrency/welcome-async.html"
"async/pitfall/async-traits.html" = "../async-pitfalls/async-traits.html"
"async/pitfalls/async-traits.html" = "../concurrency/async-pitfalls/async-traits.html"
"async/pitfalls/blocking-executor.html" = "../concurrency/async-pitfalls/blocking-executor.html"
"async/pitfalls/cancellation.html" = "../concurrency/async-pitfalls/cancellation.html"
"async/pitfalls.html" = "../concurrency/async-pitfalls.html"
"async/pitfalls/pin.html" = "../concurrency/async-pitfalls/pin.html"
"async/runtimes.html" = "../concurrency/async/runtimes.html"
"async/runtimes/tokio.html" = "../concurrency/async/runtimes/tokio.html"
"async/tasks.html" = "../concurrency/async/tasks.html"
"basic-syntax/compound-types.html" = "../tuples-and-arrays/tuples-and-arrays.html"
"basic-syntax/functions-interlude.html" = "../control-flow-basics/functions.html"
"basic-syntax/functions.html" = "../control-flow-basics/functions.html"
"basic-syntax/functions-interlude.html" = "../control-flow-basics/functions.html"
"basic-syntax.html" = "control-flow-basics.html"
"basic-syntax/methods.html" = "../control-flow-basics/functions.html"
"basic-syntax/references-dangling.html" = "../references/shared.html"
"basic-syntax/references.html" = "../references/shared.html"
Expand All @@ -94,11 +107,17 @@ use-boolean-and = true
"basic-syntax/string-slices.html" = "../references/strings.html"
"basic-syntax/type-inference.html" = "../types-and-values/inference.html"
"basic-syntax/variables.html" = "../types-and-values/variables.html"
"concurrency.html" = "concurrency/welcome.html"
"concurrency/scoped-threads.html" = "threads/scoped.html"
"concurrency/shared_state/arc.html" = "../shared-state/arc.html"
"concurrency/shared_state/example.html" = "../shared-state/example.html"
"concurrency/shared_state.html" = "shared-state.html"
"concurrency/shared_state/mutex.html" = "../shared-state/mutex.html"
"control-flow-basics/conditionals.html" = "if.html"
"control-flow.html" = "control-flow-basics.html"
"control-flow/blocks.html" = "../control-flow-basics/blocks-and-scopes.html"
"control-flow/break-continue.html" = "../control-flow-basics/break-continue.html"
"control-flow/for-expressions.html" = "../control-flow-basics/loops.html"
"control-flow.html" = "control-flow-basics.html"
"control-flow/if-expressions.html" = "../control-flow-basics/conditionals.html"
"control-flow/if-let-expressions.html" = "../pattern-matching/let-control-flow.html"
"control-flow/loop-expressions.html" = "../control-flow-basics/loops.html"
Expand All @@ -118,7 +137,15 @@ use-boolean-and = true
"error-handling/panic-unwind.html" = "../error-handling/panics.html"
"error-handling/result.html" = "../std-types/result.html"
"error-handling/try-operator.html" = "../error-handling/try.html"
"exercises/concurrency/afternoon.html" = "../../concurrency/async-exercises.html"
"exercises/concurrency/chat-app.html" = "../../concurrency/async-exercises/chat-app.html"
"exercises/concurrency/dining-philosophers-async.html" = "../../concurrency/async-exercises/dining-philosophers.html"
"exercises/concurrency/dining-philosophers.html" = "../../concurrency/sync-exercises/dining-philosophers.html"
"exercises/concurrency/elevator.html" = "chat-app.html"
"exercises/concurrency/link-checker.html" = "../../concurrency/sync-exercises/link-checker.html"
"exercises/concurrency/morning.html" = "../../concurrency/sync-exercises.html"
"exercises/concurrency/solutions-afternoon.html" = "../../concurrency/async-exercises/solutions.html"
"exercises/concurrency/solutions-morning.html" = "../../concurrency/sync-exercises/solutions.html"
"exercises/day-1/afternoon.html" = "../../control-flow-basics/exercise.html"
"exercises/day-1/book-library.html" = "../day-2/book-library.html"
"exercises/day-1/for-loops.html" = "../../tuples-and-arrays/exercise.html"
Expand Down Expand Up @@ -161,22 +188,22 @@ use-boolean-and = true
"memory-management/manual.html" = "../memory-management/approaches.html"
"memory-management/rust.html" = "../memory-management/ownership.html"
"memory-management/scope-based.html" = "../memory-management/approaches.html"
"memory-management/stack-vs-heap.html" = "../memory-management/review.html"
"memory-management/stack.html" = "../memory-management/review.html"
"memory-management/stack-vs-heap.html" = "../memory-management/review.html"
"methods-and-traits/trait-objects.html" = "../smart-pointers/trait-objects.html"
"methods.html" = "methods-and-traits/methods.html"
"methods/example.html" = "../methods-and-traits/methods.html"
"methods.html" = "methods-and-traits/methods.html"
"methods/receiver.html" = "../methods-and-traits/methods.html"
"outros-recursos.html" = "other-resources.html"
"ownership.html" = "memory-management/ownership.html"
"ownership/borrowing.html" = "../borrowing/shared.html"
"ownership/copy-clone.html" = "../memory-management/copy-types.html"
"ownership/double-free-modern-cpp.html" = "../memory-management/move.html"
"ownership.html" = "memory-management/ownership.html"
"ownership/lifetimes-data-structures.html" = "../lifetimes/struct-lifetimes.html"
"ownership/lifetimes-function-calls.html" = "../lifetimes/lifetime-elision.html"
"ownership/lifetimes.html" = "../lifetimes/lifetime-annotations.html"
"ownership/move-semantics.html" = "../memory-management/move.html"
"ownership/moved-strings-rust.html" = "../memory-management/move.html"
"ownership/move-semantics.html" = "../memory-management/move.html"
"ownership/moves-function-calls.html" = "../memory-management/move.html"
"ownership/shared-unique-borrows.html" = "../borrowing/shared.html"
"pattern-matching/destructuring-arrays.html" = "../tuples-and-arrays/destructuring.html"
Expand All @@ -185,41 +212,41 @@ use-boolean-and = true
"pattern-matching/match-guards.html" = "../tuples-and-arrays/match.html"
"running-the-course/day-4.html" = "course-structure.html"
"sintaxe-básica/funções-interlude.html" = "../basic-syntax/functions-interlude.html"
"slices-and-lifetimes.html" = "lifetimes.html"
"slices-and-lifetimes/exercise.html" = "../lifetimes/exercise.html"
"slices-and-lifetimes.html" = "lifetimes.html"
"slices-and-lifetimes/lifetime-annotations.html" = "../lifetimes/lifetime-annotations.html"
"slices-and-lifetimes/lifetime-elision.html" = "../lifetimes/lifetime-elision.html"
"slices-and-lifetimes/slices.html" = "../references/slices.html"
"slices-and-lifetimes/solution.html" = "../lifetimes/solution.html"
"slices-and-lifetimes/str.html" = "../references/strings.html"
"slices-and-lifetimes/struct-lifetimes.html" = "../lifetimes/struct-lifetimes.html"
"std.html" = "std-types/std.html"
"std/box.html" = "../smart-pointers/box.html"
"std/box-niche.html" = "../smart-pointers/box.html"
"std/box-recursive.html" = "../smart-pointers/box.html"
"std/box.html" = "../smart-pointers/box.html"
"std/cell.html" = "../borrowing/interior-mutability.html"
"std/hashmap.html" = "../std-types/hashmap.html"
"std.html" = "std-types/std.html"
"std/option-result.html" = "../std-types/option.html"
"std/rc.html" = "../smart-pointers/rc.html"
"std/string.html" = "../std-types/string.html"
"std/vec.html" = "../std-types/vec.html"
"structs.html" = "user-defined-types/named-structs.html"
"structs/field-shorthand.html" = "../user-defined-types/named-structs.html"
"structs.html" = "user-defined-types/named-structs.html"
"structs/tuple-structs.html" = "../user-defined-types/tuple-structs.html"
"structure.html" = "running-the-course/course-structure.html"
"testing/doc-tests.html" = "../testing/other.html"
"testing/googletest.html" = "../android/testing/googletest.html"
"testing/integration-tests.html" = "../testing/other.html"
"testing/mockall.html" = "../android/testing/mockall.html"
"testing/useful-crates.html" = "../testing.html"
"traits.html" = "methods-and-traits/traits.html"
"traits/closures.html" = "../std-traits/closures.html"
"traits/default-methods.html" = "../methods-and-traits/traits.html"
"traits/default.html" = "../std-traits/default.html"
"traits/default-methods.html" = "../methods-and-traits/traits.html"
"traits/deriving-traits.html" = "../methods-and-traits/deriving.html"
"traits/drop.html" = "../memory-management/drop.html"
"traits/from-into.html" = "../std-traits/from-and-into.html"
"traits/from-iterator.html" = "../iterators/fromiterator.html"
"traits.html" = "methods-and-traits/traits.html"
"traits/impl-trait.html" = "../generics/impl-trait.html"
"traits/important-traits.html" = "../std-traits/comparisons.html"
"traits/iterator.html" = "../iterators/iterators.html"
Expand All @@ -228,10 +255,11 @@ use-boolean-and = true
"traits/trait-bounds.html" = "../generics/trait-bounds.html"
"traits/trait-objects.html" = "../smart-pointers/trait-objects.html"
"tuples-and-arrays/match.html" = "../pattern-matching/match.html"
"tuples-and-arrays/tuples-and-arrays.html" = "tuples.html"
"types-and-values/strings.html" = "../references/strings.html"
"unsafe.html" = "unsafe-rust/unsafe.html"
"unsafe/calling-unsafe-functions.html" = "../unsafe-rust/unsafe-functions.html"
"unsafe/extern-functions.html" = "../unsafe-rust/unsafe-functions.html"
"unsafe.html" = "unsafe-rust/unsafe.html"
"unsafe/mutable-static-variables.html" = "../unsafe-rust/mutable-static.html"
"unsafe/mutable-static-variables.md" = "mutable-static-variables.html"
"unsafe/raw-pointers.html" = "../unsafe-rust/dereferencing.html"
Expand All @@ -243,9 +271,9 @@ use-boolean-and = true
"welcome-bare-metal.html" = "bare-metal.html"
"welcome-day-1/what-is-rust.html" = "../hello-world/what-is-rust.html"
"welcome.html" = "./"
"why-rust.html" = "hello-world/benefits.html"
"why-rust/an-example-in-c.html" = "../hello-world/example.html"
"why-rust/compile-time.html" = "../hello-world/benefits.html"
"why-rust.html" = "hello-world/benefits.html"
"why-rust/modern.html" = "../hello-world/benefits.html"
"why-rust/runtime.html" = "../hello-world/benefits.html"

Expand Down
4 changes: 2 additions & 2 deletions mdbook-course/src/replacements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn replace(
return;
};
chapter.content = DIRECTIVE
.replace(&chapter.content, |captures: &regex::Captures| {
.replace_all(&chapter.content, |captures: &regex::Captures| {
let directive_str = captures[1].trim();
let directive: Vec<_> = directive_str.split_whitespace().collect();
match directive.as_slice() {
Expand All @@ -50,7 +50,7 @@ pub fn replace(
}
["course", "outline", course_name] => {
let Some(course) = courses.find_course(course_name) else {
return captures[0].to_string();
return format!("not found - {}", captures[0].to_string());
};
course.schedule()
}
Expand Down
62 changes: 33 additions & 29 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,46 +353,50 @@

---

- [Welcome](concurrency.md)
- [Welcome](concurrency/welcome.md)
- [Threads](concurrency/threads.md)
- [Scoped Threads](concurrency/scoped-threads.md)
- [Plain Threads](concurrency/threads/plain.md)
- [Scoped Threads](concurrency/threads/scoped.md)
- [Channels](concurrency/channels.md)
- [Senders and Reveivers](concurrency/channels/senders-receivers.md)
- [Unbounded Channels](concurrency/channels/unbounded.md)
- [Bounded Channels](concurrency/channels/bounded.md)
- [`Send` and `Sync`](concurrency/send-sync.md)
- [Marker Traits](concurrency/send-sync/marker-traits.md)
- [`Send`](concurrency/send-sync/send.md)
- [`Sync`](concurrency/send-sync/sync.md)
- [Examples](concurrency/send-sync/examples.md)
- [Shared State](concurrency/shared_state.md)
- [`Arc`](concurrency/shared_state/arc.md)
- [`Mutex`](concurrency/shared_state/mutex.md)
- [Example](concurrency/shared_state/example.md)
- [Exercises](exercises/concurrency/morning.md)
- [Dining Philosophers](exercises/concurrency/dining-philosophers.md)
- [Multi-threaded Link Checker](exercises/concurrency/link-checker.md)
- [Solutions](exercises/concurrency/solutions-morning.md)
- [Shared State](concurrency/shared-state.md)
- [`Arc`](concurrency/shared-state/arc.md)
- [`Mutex`](concurrency/shared-state/mutex.md)
- [Example](concurrency/shared-state/example.md)
- [Exercises](concurrency/sync-exercises.md)
- [Dining Philosophers](concurrency/sync-exercises/dining-philosophers.md)
- [Multi-threaded Link Checker](concurrency/sync-exercises/link-checker.md)
- [Solutions](concurrency/sync-exercises/solutions.md)

# Concurrency: Afternoon

- [Async Basics](async.md)
- [`async`/`await`](async/async-await.md)
- [Futures](async/futures.md)
- [Runtimes](async/runtimes.md)
- [Tokio](async/runtimes/tokio.md)
- [Tasks](async/tasks.md)
- [Async Channels](async/channels.md)
- [Control Flow](async/control-flow.md)
- [Join](async/control-flow/join.md)
- [Select](async/control-flow/select.md)
- [Pitfalls](async/pitfalls.md)
- [Blocking the Executor](async/pitfalls/blocking-executor.md)
- [`Pin`](async/pitfalls/pin.md)
- [Async Traits](async/pitfalls/async-traits.md)
- [Cancellation](async/pitfalls/cancellation.md)
- [Exercises](exercises/concurrency/afternoon.md)
- [Dining Philosophers](exercises/concurrency/dining-philosophers-async.md)
- [Broadcast Chat Application](exercises/concurrency/chat-app.md)
- [Solutions](exercises/concurrency/solutions-afternoon.md)
- [Welcome](concurrency/welcome-async.md)
- [Async Basics](concurrency/async.md)
- [`async`/`await`](concurrency/async/async-await.md)
- [Futures](concurrency/async/futures.md)
- [Runtimes](concurrency/async/runtimes.md)
- [Tokio](concurrency/async/runtimes/tokio.md)
- [Tasks](concurrency/async/tasks.md)
- [Channels and Control Flow](concurrency/async-control-flow.md)
- [Async Channels](concurrency/async-control-flow/channels.md)
- [Join](concurrency/async-control-flow/join.md)
- [Select](concurrency/async-control-flow/select.md)
- [Pitfalls](concurrency/async-pitfalls.md)
- [Blocking the Executor](concurrency/async-pitfalls/blocking-executor.md)
- [`Pin`](concurrency/async-pitfalls/pin.md)
- [Async Traits](concurrency/async-pitfalls/async-traits.md)
- [Cancellation](concurrency/async-pitfalls/cancellation.md)
- [Exercises](concurrency/async-exercises.md)
- [Dining Philosophers](concurrency/async-exercises/dining-philosophers.md)
- [Broadcast Chat Application](concurrency/async-exercises/chat-app.md)
- [Solutions](concurrency/async-exercises/solutions.md)

# Final Words

Expand Down
7 changes: 0 additions & 7 deletions src/async/control-flow.md

This file was deleted.

3 changes: 3 additions & 0 deletions src/concurrency/async-control-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Channels and Control Flow

{{%segment outline}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
minutes: 8
---

# Async Channels

Several crates have support for asynchronous channels. For instance `tokio`:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
minutes: 4
---

# Join

A join operation waits until all of a set of futures are ready, and returns a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
minutes: 5
---

# Select

A select operation waits until any of a set of futures is ready, and responds to
Expand Down
3 changes: 3 additions & 0 deletions src/concurrency/async-exercises.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Exercises

{{%segment outline}}
1 change: 1 addition & 0 deletions src/concurrency/async-exercises/afternoon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Exercises
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
minutes: 30
---

# Broadcast Chat Application

In this exercise, we want to use our new knowledge to implement a broadcast chat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
minutes: 20
---

# Dining Philosophers --- Async

See [dining philosophers](dining-philosophers.md) for a description of the
Expand All @@ -11,17 +15,17 @@ code below to a file called `src/main.rs`, fill out the blanks, and test that
<!-- File src/main.rs -->

```rust,compile_fail
{{#include dining-philosophers-async.rs:Philosopher}}
{{#include dining-philosophers.rs:Philosopher}}
// left_fork: ...
// right_fork: ...
// thoughts: ...
}
{{#include dining-philosophers-async.rs:Philosopher-think}}
{{#include dining-philosophers.rs:Philosopher-think}}
{{#include dining-philosophers-async.rs:Philosopher-eat}}
{{#include dining-philosophers-async.rs:Philosopher-eat-body}}
{{#include dining-philosophers-async.rs:Philosopher-eat-end}}
{{#include dining-philosophers.rs:Philosopher-eat}}
{{#include dining-philosophers.rs:Philosopher-eat-body}}
{{#include dining-philosophers.rs:Philosopher-eat-end}}
// Create forks
// Create philosophers
Expand Down
Loading

0 comments on commit face5af

Please sign in to comment.