equal
deleted
inserted
replaced
25 end; |
25 end; |
26 |
26 |
27 structure Multithreading: MULTITHREADING = |
27 structure Multithreading: MULTITHREADING = |
28 struct |
28 struct |
29 |
29 |
30 (* options *) |
30 (* tracing *) |
31 |
31 |
32 val trace = ref 0; |
32 val trace = ref 0; |
33 |
33 |
34 fun tracing level msg = |
34 fun tracing level msg = |
35 if level > ! trace then () |
35 if level > ! trace then () |
41 (if Time.>= (time, Time.fromMilliseconds 1000) then 1 |
41 (if Time.>= (time, Time.fromMilliseconds 1000) then 1 |
42 else if Time.>= (time, Time.fromMilliseconds 100) then 2 |
42 else if Time.>= (time, Time.fromMilliseconds 100) then 2 |
43 else if Time.>= (time, Time.fromMilliseconds 10) then 3 |
43 else if Time.>= (time, Time.fromMilliseconds 10) then 3 |
44 else if Time.>= (time, Time.fromMilliseconds 1) then 4 else 5); |
44 else if Time.>= (time, Time.fromMilliseconds 1) then 4 else 5); |
45 |
45 |
|
46 fun real_time f x = |
|
47 let |
|
48 val timer = Timer.startRealTimer (); |
|
49 val () = f x; |
|
50 val time = Timer.checkRealTimer timer; |
|
51 in time end; |
|
52 |
|
53 |
|
54 (* options *) |
46 |
55 |
47 val available = true; |
56 val available = true; |
48 |
57 |
49 val max_threads = ref 0; |
58 val max_threads = ref 0; |
50 |
59 |
218 val name' = ! critical_name; |
227 val name' = ! critical_name; |
219 val _ = |
228 val _ = |
220 if Mutex.trylock critical_lock then () |
229 if Mutex.trylock critical_lock then () |
221 else |
230 else |
222 let |
231 let |
223 val timer = Timer.startRealTimer (); |
|
224 val _ = tracing 5 (fn () => "CRITICAL" ^ show name ^ show' name' ^ ": waiting"); |
232 val _ = tracing 5 (fn () => "CRITICAL" ^ show name ^ show' name' ^ ": waiting"); |
225 val _ = Mutex.lock critical_lock; |
233 val time = real_time Mutex.lock critical_lock; |
226 val time = Timer.checkRealTimer timer; |
|
227 val _ = tracing_time time (fn () => |
234 val _ = tracing_time time (fn () => |
228 "CRITICAL" ^ show name ^ show' name' ^ ": passed after " ^ Time.toString time); |
235 "CRITICAL" ^ show name ^ show' name' ^ ": passed after " ^ Time.toString time); |
229 in () end; |
236 in () end; |
230 val _ = critical_thread := SOME (Thread.self ()); |
237 val _ = critical_thread := SOME (Thread.self ()); |
231 val _ = critical_name := name; |
238 val _ = critical_name := name; |