Skip to content

Commit

Permalink
Prepare L10 flipped note
Browse files Browse the repository at this point in the history
  • Loading branch information
h365chen committed Jan 26, 2024
1 parent 3efc953 commit fb9c6d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lectures/flipped/L10.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
# Lecture 10: Locks, Reentrancy
# Lecture 10 — Use of Locks, Reentrancy

Producer-consumer: have students shrink the critical section in `lectures/live-coding/L10/producer-consumer` and measure the perf diff:
## Roadmap

We will talk about how to appropriately use locks.

## Exercise: Producer-Consumer (10 min)

have students shrink the critical section in
`lectures/live-coding/L10/producer-consumer` and measure the perf diff:

> hyperfine --warmup 1 --m 5 "cargo run --release"
## Mini-lecture

Discuss the 3 major concerns with locks.

Do the proof about consistent ordering.

Trylock example: here's a deadlock from stackoverflow: https://stackoverflow.com/questions/55958941/how-can-i-create-a-deadlock-with-rust
## Trylock

Trylock example: here's a deadlock from stackoverflow:
https://stackoverflow.com/questions/55958941/how-can-i-create-a-deadlock-with-rust

Convert it to use trylocks and not deadlock. Of course you can't just unwrap()
anymore. How can you measure the time spent waiting? See
https://rust-lang-nursery.github.io/rust-cookbook/datetime/duration.html

Convert it to use trylocks and not deadlock. Of course you can't just unwrap() anymore. How can you measure the time spent waiting? (https://rust-lang-nursery.github.io/rust-cookbook/datetime/duration.html)

```rust
/*
Expand Down
2 changes: 2 additions & 0 deletions lectures/flipped/L10_trylock.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# L10 trylock solution

Convert the code in L10.md to use trylocks and not deadlock. The main idea is to
release the resources if trylock fails and then try again.

Expand Down

0 comments on commit fb9c6d6

Please sign in to comment.