Skip to content

Commit 6856c29

Browse files
slides
1 parent eba56f4 commit 6856c29

File tree

2 files changed

+8389
-3975
lines changed

2 files changed

+8389
-3975
lines changed

slides/index.html

Lines changed: 8379 additions & 3959 deletions
Large diffs are not rendered by default.

slides/index.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -834,27 +834,21 @@ Associate mutable state with locks, ensuring exclusive access. Capsules use the
834834

835835
{pause #capsules}
836836

837-
⚠️ **A simpler interface is coming, the following may hurt your eyes** ⚠️
838-
839-
{pause}
840-
841837
```ocaml
842-
let gensym =
843-
(* 1. Create capsule and get key *)
844-
let (P key) = Capsule.create () in
838+
let gensym =
839+
(* Create a capsule guarded by a mutex and unpack to get the brand. *)
840+
let (P mutex) = Capsule.Mutex.create () in
845841
846-
(* 2. Create encapsulated data *)
842+
(* Create encapsulated data bound to the same key brand. *)
847843
let counter = Capsule.Data.create (fun () -> ref 0) in
848844
849-
let mutex = Capsule.Mutex.create key in (* 3. Create mutex from key *)
850-
851-
(* 4. Access with lock *)
852-
let fetch_and_incr () =
853-
Capsule.Mutex.with_lock mutex ~f:(fun password ->
854-
Capsule.Data.extract counter ~password ~f:(fun c ->
855-
c := !c + 1; !c))
845+
(* Access the data, requiring a capability to wait/block. *)
846+
let fetch_and_incr (w : Await.t) =
847+
Capsule.Mutex.with_lock w mutex ~f:(fun access ->
848+
let c = Capsule.Data.unwrap ~access counter in
849+
c := !c + 1; !c)
856850
in
857-
fun () -> "gsym_" ^ (Int.to_string (fetch_and_incr ()))
851+
fun w -> "gsym_" ^ Int.to_string (fetch_and_incr w)
858852
```
859853

860854
{pause up}

0 commit comments

Comments
 (0)