File: sing.ml

package info (click to toggle)
cothreads 0.10-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 500 kB
  • sloc: ml: 1,963; makefile: 216
file content (15 lines) | stat: -rw-r--r-- 385 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Thread=Cothread
open Stm

let tv = tvar 10

let rec run op t =
  Thread.delay (Random.float t);
  atom (read_tvar tv >>= fun x -> 
          Printf.printf "I read %d\n" x; flush_all ();
          write_tvar tv (op x));
  run op t

let th1 = Thread.create (run (fun x -> x * 2 + 1)) 0.5
let th2 = Thread.create (run (fun x -> x / 2)) 1.0
let _ = Thread.join th1; Thread.join th2