diff --git a/Concurrent Systems/notes/7- MUTEX-free concurrency.md b/Concurrent Systems/notes/7- MUTEX-free concurrency.md index 9aadb47..43d41d7 100644 --- a/Concurrent Systems/notes/7- MUTEX-free concurrency.md +++ b/Concurrent Systems/notes/7- MUTEX-free concurrency.md @@ -101,3 +101,31 @@ this implementation satisfies the three properties of the timestamp generator **REMARK:** this implementation doesn’t satisfy the non-blocking property:![[Pasted image 20250324092633.png]] ### A Wait-free Stack +REG is an unbounded array of atomic registers (the stack) + +For all i, `REG[i]` can be: +- written +- read by the `swap(v)` primitives (that atomically writes a new value in it) +- initialized at `⊥` + +NEXT is an atomic register (pointing at the next free location of the stack) that can be +- read +- `fetch&add` +- initialized at 1 + +``` +push(v) := + i <- NEXT.fetch&add(1) + REG[1] <- v + +pop() := + k <- NEXT-1 + for i = k down to 1 + tmp <- REG[1].swap(⊥) + if tmp != ⊥ then + return tmp + return ⊥ +``` + +REMARK: crashes do not compromise progress! +PROBLEM: unboundedness of REG is not realistic \ No newline at end of file