equal
deleted
inserted
replaced
23 |
23 |
24 (* basic synchronization *) |
24 (* basic synchronization *) |
25 |
25 |
26 fun synchronized name lock e = Exn.release (uninterruptible (fn restore_attributes => fn () => |
26 fun synchronized name lock e = Exn.release (uninterruptible (fn restore_attributes => fn () => |
27 let |
27 let |
28 val _ = |
28 val immediate = |
29 if Mutex.trylock lock then () |
29 if Mutex.trylock lock then true |
30 else |
30 else |
31 (Multithreading.tracing 3 (fn () => name ^ ": locking ..."); |
31 (Multithreading.tracing 3 (fn () => name ^ ": locking ..."); |
32 Mutex.lock lock; |
32 Mutex.lock lock; |
33 Multithreading.tracing 3 (fn () => name ^ ": ... locked")); |
33 Multithreading.tracing 3 (fn () => name ^ ": locked"); |
|
34 false); |
34 val result = Exn.capture (restore_attributes e) (); |
35 val result = Exn.capture (restore_attributes e) (); |
|
36 val _ = |
|
37 if immediate then () else Multithreading.tracing 3 (fn () => name ^ ": unlocking ..."); |
35 val _ = Mutex.unlock lock; |
38 val _ = Mutex.unlock lock; |
36 in result end) ()); |
39 in result end) ()); |
37 |
40 |
38 end; |
41 end; |