equal
deleted
inserted
replaced
16 structure Single_Assignment: SINGLE_ASSIGNMENT = |
16 structure Single_Assignment: SINGLE_ASSIGNMENT = |
17 struct |
17 struct |
18 |
18 |
19 datatype 'a state = |
19 datatype 'a state = |
20 Set of 'a |
20 Set of 'a |
21 | Unset of {lock: Mutex.mutex, cond: ConditionVar.conditionVar}; |
21 | Unset of {lock: Thread.Mutex.mutex, cond: Thread.ConditionVar.conditionVar}; |
22 |
22 |
23 fun init_state () = |
23 fun init_state () = |
24 Unset {lock = Mutex.mutex (), cond = ConditionVar.conditionVar ()}; |
24 Unset {lock = Thread.Mutex.mutex (), cond = Thread.ConditionVar.conditionVar ()}; |
25 |
25 |
26 abstype 'a var = Var of {name: string, state: 'a state Unsynchronized.ref} |
26 abstype 'a var = Var of {name: string, state: 'a state Unsynchronized.ref} |
27 with |
27 with |
28 |
28 |
29 fun var name = Var {name = name, state = Unsynchronized.ref (init_state ())}; |
29 fun var name = Var {name = name, state = Unsynchronized.ref (init_state ())}; |
60 Multithreading.synchronized name lock (fn () => |
60 Multithreading.synchronized name lock (fn () => |
61 (case ! state of |
61 (case ! state of |
62 Set _ => assign_fail name |
62 Set _ => assign_fail name |
63 | Unset _ => |
63 | Unset _ => |
64 Thread_Attributes.uninterruptible (fn _ => fn () => |
64 Thread_Attributes.uninterruptible (fn _ => fn () => |
65 (state := Set x; RunCall.clearMutableBit state; ConditionVar.broadcast cond)) ()))); |
65 (state := Set x; RunCall.clearMutableBit state; |
|
66 Thread.ConditionVar.broadcast cond)) ()))); |
66 |
67 |
67 end; |
68 end; |
68 |
69 |
69 end; |
70 end; |