equal
deleted
inserted
replaced
15 val has_running_threads : string -> bool |
15 val has_running_threads : string -> bool |
16 end; |
16 end; |
17 |
17 |
18 structure Async_Manager_Legacy : ASYNC_MANAGER_LEGACY = |
18 structure Async_Manager_Legacy : ASYNC_MANAGER_LEGACY = |
19 struct |
19 struct |
20 |
|
21 fun make_thread interrupts body = |
|
22 Isabelle_Thread.fork {name = "async_manager", stack_limit = NONE, interrupts = interrupts} body; |
|
23 |
20 |
24 fun implode_message (workers, work) = |
21 fun implode_message (workers, work) = |
25 space_implode " " (Try.serial_commas "and" workers) ^ work |
22 space_implode " " (Try.serial_commas "and" workers) ^ work |
26 |
23 |
27 structure Thread_Heap = Heap |
24 structure Thread_Heap = Heap |
84 |> writeln) |
81 |> writeln) |
85 |
82 |
86 fun check_thread_manager () = Synchronized.change global_state |
83 fun check_thread_manager () = Synchronized.change global_state |
87 (fn state as {manager, timeout_heap, active, canceling, messages} => |
84 (fn state as {manager, timeout_heap, active, canceling, messages} => |
88 if (case manager of SOME thread => Isabelle_Thread.is_active thread | NONE => false) then state |
85 if (case manager of SOME thread => Isabelle_Thread.is_active thread | NONE => false) then state |
89 else let val manager = SOME (make_thread false (fn () => |
86 else let val manager = SOME (Isabelle_Thread.fork (Isabelle_Thread.params "async_manager") (fn () => |
90 let |
87 let |
91 fun time_limit timeout_heap = |
88 fun time_limit timeout_heap = |
92 (case try Thread_Heap.min timeout_heap of |
89 (case try Thread_Heap.min timeout_heap of |
93 NONE => Time.now () + max_wait_time |
90 NONE => Time.now () + max_wait_time |
94 | SOME (time, _) => time) |
91 | SOME (time, _) => time) |
133 val state' = make_state manager timeout_heap' active' canceling messages |
130 val state' = make_state manager timeout_heap' active' canceling messages |
134 in state' end); |
131 in state' end); |
135 check_thread_manager ()) |
132 check_thread_manager ()) |
136 |
133 |
137 fun thread tool birth_time death_time desc f = |
134 fun thread tool birth_time death_time desc f = |
138 (make_thread true |
135 (Isabelle_Thread.fork (Isabelle_Thread.params "async_manager" |> Isabelle_Thread.interrupts) |
139 (fn () => |
136 (fn () => |
140 let |
137 let |
141 val self = Isabelle_Thread.self () |
138 val self = Isabelle_Thread.self () |
142 val _ = register tool birth_time death_time desc self |
139 val _ = register tool birth_time death_time desc self |
143 in unregister (f ()) self end); |
140 in unregister (f ()) self end); |