File: Test025.ML

package info (click to toggle)
polyml 5.6-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,892 kB
  • ctags: 34,453
  • sloc: cpp: 44,983; ansic: 24,520; asm: 14,850; sh: 11,730; makefile: 551; exp: 484; python: 253; awk: 91; sed: 9
file content (28 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(* Check that locks work correctly. *)

open Thread.Thread Thread.Mutex

val a = ref 0 and b = ref 0 and c = ref 0

val mut = mutex()

fun f s n () =
let
   val () = lock mut
   val aa = (a := !a+1; !a)
   and bb = (b := !b+1; !b)
   and cc = (c := !c+1; !c)
   val () = unlock mut
in
   if aa <> bb orelse aa <> cc orelse bb <> cc
   then print(concat[s, "-> a = ", Int.toString aa, " b  = ",
                     Int.toString bb, " c  = ", Int.toString cc, "\n"])
   else if aa < 10000
   then f s (n+1) ()
   else ()
end;

fork(f "A" 0, [InterruptState InterruptAsynch, EnableBroadcastInterrupt true]);
fork(f "B" 0, [InterruptState InterruptAsynch, EnableBroadcastInterrupt true]);
fork(f "C" 0, [InterruptState InterruptAsynch, EnableBroadcastInterrupt true]);
f "D" 0 ();