Skip to content

Commit

Permalink
Prepare L14 flipped note
Browse files Browse the repository at this point in the history
  • Loading branch information
h365chen committed Feb 5, 2024
1 parent f318d78 commit cb5cff9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lectures/flipped/L11.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ fn main() {
Discuss about non-blocking, blocking, lock-free, and wait-free. See
<https://www.justsoftwaresolutions.co.uk/threading/non_blocking_lock_free_and_wait_free.html>

Also, <https://preshing.com/20120612/an-introduction-to-lock-free-programming/>

A quick summary:

- non-blocking/blocking: blocking does not cost CPU time, but non-blocking does
Expand Down
28 changes: 24 additions & 4 deletions lectures/flipped/L14.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Lecture 14 — Memory Consistency

## Roadmap

We will talk about compiler reordering, hardware reordering, and memory
consistency models.

## Context: reordering, e.g. as done by compilers.

Question: if accessing `thing.y` takes a long time, how can we speed up the
Expand All @@ -14,7 +19,8 @@ a = b + c;

## Hardware reordering

hey look! The compiler can still generate code and we get what we don't expect!
Hey look! The compiler can still generate code and we get what we don't expect!
But for now let's say we convince the compiler to emit the following logic.

Question: what are possible final values for `y`?

Expand Down Expand Up @@ -47,11 +53,13 @@ One definition of something we might want:
## Memory consistency models

Talk about *memory barrier* or *fence*; mfence, sfence, lfence example.
Talk about *memory barrier* or *fence*; mfence, sfence, lfence examples (x86
architecture).

* Acquire / Release

From the [Rustonomicon's page](https://doc.rust-lang.org/nomicon/atomics.html#acquire-release)
From the [Rustonomicon's
page](https://doc.rust-lang.org/nomicon/atomics.html#acquire-release)

> When thread A releases a location in memory and then thread B subsequently
> acquires the same location in memory, causality is established. Every write
Expand Down Expand Up @@ -130,6 +138,18 @@ simply a mechanism to propagate a newly written value. The memory consistency
model is the policy that places the bounds on when the value can be propagated
to a given processor."

## TODO: build a communication server?

The entire lecture may be wrapped as a game, where students connect to the same
server to read/write values; the server, however, uses the weird source control
strategy (see
[here](https://preshing.com/20120710/memory-barriers-are-like-source-control-operations/)
to respond the reads/writes. In the end, each student can see the changes in the
correct order, but other students see them in a different order. Then they can
inject "fence" to ensure other students see the same order as themselves see it.

# After-action report, plam, 27 Feb 2023

I did a bit of reorg in the above notes. It's still not very flipped. But I kind of did the whole thing, and did not talk about cache coherence. Did not check the runtime between SeqCst and Relaxed.
I did a bit of reorg in the above notes. It's still not very flipped. But I kind
of did the whole thing, and did not talk about cache coherence. Did not check
the runtime between SeqCst and Relaxed.

0 comments on commit cb5cff9

Please sign in to comment.