/usr/share/doc/libcothreads-ocaml-dev/examples/lock.ml is in libcothreads-ocaml-dev 0.10-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | module Thread=Cothread (* Or just use Thread, no difference *)
open Thread
let lk1 = Mutex.create ()
let lk2 = Mutex.create ()
let rec run x =
Mutex.lock lk1;
Printf.printf "%d takes lock 1\n" x; flush stdout;
Mutex.lock lk2;
Printf.printf "%d takes lock 2\n" x; flush stdout;
Mutex.unlock lk2;
Printf.printf "%d release lock 2\n" x; flush stdout;
Mutex.unlock lk1;
Printf.printf "%d release lock 1\n" x; flush stdout;
Thread.delay (Random.float 0.2);
run x
let _ =
ignore (Array.init 10 (Thread.create run));
while true do Thread.delay 5.0 done
|