| author | wenzelm |
| Mon, 27 Jul 2015 22:08:46 +0200 | |
| changeset 60803 | e11f47dd0786 |
| parent 60764 | b610ba36e02c |
| child 61312 | 6d779a71086d |
| permissions | -rw-r--r-- |
|
59471
ca459352d8c5
more explicit indication of Async_Manager_Legacy as Proof General legacy;
wenzelm
parents:
59468
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/async_manager_legacy.ML |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Muenchen |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
3 |
Author: Makarius |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
4 |
Author: Jasmin Blanchette, TU Muenchen |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
5 |
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
6 |
Central manager for asynchronous diagnosis tool threads. |
| 58894 | 7 |
|
8 |
Proof General legacy! |
|
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
9 |
*) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
10 |
|
|
59471
ca459352d8c5
more explicit indication of Async_Manager_Legacy as Proof General legacy;
wenzelm
parents:
59468
diff
changeset
|
11 |
signature ASYNC_MANAGER_LEGACY = |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
12 |
sig |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
13 |
val break_into_chunks : string -> string list |
| 57556 | 14 |
val thread : string -> Time.time -> Time.time -> string * string -> (unit -> bool * string) -> |
15 |
unit |
|
| 37585 | 16 |
val kill_threads : string -> string -> unit |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
17 |
val has_running_threads : string -> bool |
| 37585 | 18 |
val running_threads : string -> string -> unit |
19 |
val thread_messages : string -> string -> int option -> unit |
|
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
20 |
end; |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
21 |
|
|
59471
ca459352d8c5
more explicit indication of Async_Manager_Legacy as Proof General legacy;
wenzelm
parents:
59468
diff
changeset
|
22 |
structure Async_Manager_Legacy : ASYNC_MANAGER_LEGACY = |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
23 |
struct |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
24 |
|
| 58894 | 25 |
fun make_thread interrupts body = |
26 |
Thread.fork |
|
27 |
(fn () => |
|
28 |
Runtime.debugging NONE body () handle exn => |
|
29 |
if Exn.is_interrupt exn then () |
|
30 |
else writeln ("## INTERNAL ERROR ##\n" ^ Runtime.exn_message exn),
|
|
| 60764 | 31 |
Simple_Thread.attributes |
32 |
{name = "async_manager", stack_limit = NONE, interrupts = interrupts});
|
|
| 58894 | 33 |
|
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
34 |
val message_store_limit = 20 |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
35 |
val message_display_limit = 10 |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
36 |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
37 |
fun implode_message (workers, work) = |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
38 |
space_implode " " (Try.serial_commas "and" workers) ^ work |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
39 |
|
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
40 |
structure Thread_Heap = Heap |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
41 |
( |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
42 |
type elem = Time.time * Thread.thread |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
43 |
fun ord ((a, _), (b, _)) = Time.compare (a, b) |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
44 |
) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
45 |
|
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
46 |
fun lookup_thread xs = AList.lookup Thread.equal xs |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
47 |
fun delete_thread xs = AList.delete Thread.equal xs |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
48 |
fun update_thread xs = AList.update Thread.equal xs |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
49 |
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
50 |
type state = |
| 37585 | 51 |
{manager: Thread.thread option,
|
52 |
timeout_heap: Thread_Heap.T, |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
53 |
active: |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
54 |
(Thread.thread |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
55 |
* (string * Time.time * Time.time * (string * string))) list, |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
56 |
canceling: (Thread.thread * (string * Time.time * (string * string))) list, |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
57 |
messages: (bool * (string * (string * string))) list, |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
58 |
store: (string * (string * string)) list} |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
59 |
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
60 |
fun make_state manager timeout_heap active canceling messages store : state = |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
61 |
{manager = manager, timeout_heap = timeout_heap, active = active,
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
62 |
canceling = canceling, messages = messages, store = store} |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
63 |
|
| 57556 | 64 |
val global_state = Synchronized.var "async_manager" (make_state NONE Thread_Heap.empty [] [] [] []) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
65 |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
66 |
fun unregister (urgent, message) thread = |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
67 |
Synchronized.change global_state |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
68 |
(fn state as {manager, timeout_heap, active, canceling, messages, store} =>
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
69 |
(case lookup_thread active thread of |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
70 |
SOME (tool, _, _, desc as (worker, its_desc)) => |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
71 |
let |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
72 |
val active' = delete_thread thread active |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
73 |
val now = Time.now () |
| 37585 | 74 |
val canceling' = (thread, (tool, now, desc)) :: canceling |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
75 |
val message' = |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
76 |
(worker, its_desc ^ (if message = "" then "" else "\n" ^ message)) |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
77 |
val messages' = (urgent, (tool, message')) :: messages |
| 37585 | 78 |
val store' = (tool, message') :: |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
79 |
(if length store <= message_store_limit then store |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
80 |
else #1 (chop message_store_limit store)) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
81 |
in make_state manager timeout_heap active' canceling' messages' store' end |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
82 |
| NONE => state)) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
83 |
|
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
84 |
val min_wait_time = seconds 0.3 |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
85 |
val max_wait_time = seconds 10.0 |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
86 |
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
87 |
fun replace_all bef aft = |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
88 |
let |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
89 |
fun aux seen "" = String.implode (rev seen) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
90 |
| aux seen s = |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
91 |
if String.isPrefix bef s then |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
92 |
aux seen "" ^ aft ^ aux [] (unprefix bef s) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
93 |
else |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
94 |
aux (String.sub (s, 0) :: seen) (String.extract (s, 1, NONE)) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
95 |
in aux [] end |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
96 |
|
| 57556 | 97 |
(* This is a workaround for Proof General's off-by-a-few sendback display bug, whereby "pr" in |
98 |
"proof" is not highlighted. *) |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
99 |
val break_into_chunks = space_explode "\000" o replace_all "\n\n" "\000" |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
100 |
|
| 37585 | 101 |
fun print_new_messages () = |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
102 |
Synchronized.change_result global_state |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
103 |
(fn {manager, timeout_heap, active, canceling, messages, store} =>
|
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
104 |
messages |
| 43055 | 105 |
|> List.partition |
106 |
(fn (urgent, _) => |
|
107 |
(null active andalso null canceling) orelse urgent) |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
108 |
||> (fn postponed_messages => |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
109 |
make_state manager timeout_heap active canceling |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
110 |
postponed_messages store)) |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
111 |
|> map (fn (_, (tool, (worker, work))) => ((tool, work), worker)) |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
112 |
|> AList.group (op =) |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
113 |
|> List.app (fn ((_, ""), _) => () |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
114 |
| ((tool, work), workers) => |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
115 |
tool ^ ": " ^ |
| 47945 | 116 |
implode_message (workers |> sort_distinct string_ord, work) |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
117 |
|> break_into_chunks |
| 58843 | 118 |
|> List.app writeln) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
119 |
|
|
39006
a02cb5717677
remove time information in output, since it's confusing anyway
blanchet
parents:
38990
diff
changeset
|
120 |
fun check_thread_manager () = Synchronized.change global_state |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
121 |
(fn state as {manager, timeout_heap, active, canceling, messages, store} =>
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
122 |
if (case manager of SOME thread => Thread.isActive thread | NONE => false) then state |
| 58894 | 123 |
else let val manager = SOME (make_thread false (fn () => |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
124 |
let |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
125 |
fun time_limit timeout_heap = |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
126 |
(case try Thread_Heap.min timeout_heap of |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
127 |
NONE => Time.+ (Time.now (), max_wait_time) |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
128 |
| SOME (time, _) => time) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
129 |
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
130 |
(*action: find threads whose timeout is reached, and interrupt canceling threads*) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
131 |
fun action {manager, timeout_heap, active, canceling, messages, store} =
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
132 |
let val (timeout_threads, timeout_heap') = |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
133 |
Thread_Heap.upto (Time.now (), Thread.self ()) timeout_heap |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
134 |
in |
| 37585 | 135 |
if null timeout_threads andalso null canceling then |
136 |
NONE |
|
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
137 |
else |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
138 |
let |
|
44112
ef876972fdc1
more explicit Simple_Thread.interrupt_unsynchronized, to emphasize its meaning;
wenzelm
parents:
43055
diff
changeset
|
139 |
val _ = List.app (Simple_Thread.interrupt_unsynchronized o #1) canceling |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
140 |
val canceling' = filter (Thread.isActive o #1) canceling |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
141 |
val state' = make_state manager timeout_heap' active canceling' messages store |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
142 |
in SOME (map #2 timeout_threads, state') end |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
143 |
end |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
144 |
in |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
145 |
while Synchronized.change_result global_state |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
146 |
(fn state as {timeout_heap, active, canceling, messages, store, ...} =>
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
147 |
if null active andalso null canceling andalso null messages |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
148 |
then (false, make_state NONE timeout_heap active canceling messages store) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
149 |
else (true, state)) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
150 |
do |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
151 |
(Synchronized.timed_access global_state |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
152 |
(SOME o time_limit o #timeout_heap) action |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
153 |
|> these |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
154 |
|> List.app (unregister (false, "Timed out.")); |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
155 |
print_new_messages (); |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
156 |
(* give threads some time to respond to interrupt *) |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
157 |
OS.Process.sleep min_wait_time) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
158 |
end)) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
159 |
in make_state manager timeout_heap active canceling messages store end) |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
160 |
|
|
39006
a02cb5717677
remove time information in output, since it's confusing anyway
blanchet
parents:
38990
diff
changeset
|
161 |
fun register tool birth_time death_time desc thread = |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
162 |
(Synchronized.change global_state |
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
163 |
(fn {manager, timeout_heap, active, canceling, messages, store} =>
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
164 |
let |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
165 |
val timeout_heap' = Thread_Heap.insert (death_time, thread) timeout_heap |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
166 |
val active' = update_thread (thread, (tool, birth_time, death_time, desc)) active |
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
167 |
val state' = make_state manager timeout_heap' active' canceling messages store |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
168 |
in state' end); |
|
39006
a02cb5717677
remove time information in output, since it's confusing anyway
blanchet
parents:
38990
diff
changeset
|
169 |
check_thread_manager ()) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
170 |
|
|
52048
9003b293e775
tuned signature -- emphasize thread creation here;
wenzelm
parents:
48319
diff
changeset
|
171 |
fun thread tool birth_time death_time desc f = |
| 58894 | 172 |
(make_thread true |
| 37584 | 173 |
(fn () => |
174 |
let |
|
175 |
val self = Thread.self () |
|
|
39006
a02cb5717677
remove time information in output, since it's confusing anyway
blanchet
parents:
38990
diff
changeset
|
176 |
val _ = register tool birth_time death_time desc self |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
177 |
in unregister (f ()) self end); |
| 37584 | 178 |
()) |
179 |
||
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
180 |
fun kill_threads tool das_wort_worker = Synchronized.change global_state |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
181 |
(fn {manager, timeout_heap, active, canceling, messages, store} =>
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
182 |
let |
| 37585 | 183 |
val killing = |
184 |
map_filter (fn (th, (tool', _, _, desc)) => |
|
185 |
if tool' = tool then SOME (th, (tool', Time.now (), desc)) |
|
186 |
else NONE) active |
|
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
187 |
val state' = make_state manager timeout_heap [] (killing @ canceling) messages store |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
188 |
val _ = |
|
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
189 |
if null killing then () |
| 58843 | 190 |
else writeln ("Interrupted active " ^ das_wort_worker ^ "s.")
|
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
191 |
in state' end) |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
192 |
|
| 57556 | 193 |
fun str_of_time time = string_of_int (Time.toSeconds time) ^ " s" |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
194 |
|
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
195 |
fun has_running_threads tool = |
| 57556 | 196 |
exists (fn (_, (tool', _, _, _)) => tool' = tool) (#active (Synchronized.value global_state)) |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
197 |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
198 |
fun running_threads tool das_wort_worker = |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
199 |
let |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
200 |
val {active, canceling, ...} = Synchronized.value global_state
|
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
201 |
val now = Time.now () |
| 37585 | 202 |
fun running_info (_, (tool', birth_time, death_time, desc)) = |
203 |
if tool' = tool then |
|
| 57556 | 204 |
SOME ("Running: " ^ str_of_time (Time.- (now, birth_time)) ^ " -- " ^
|
205 |
str_of_time (Time.- (death_time, now)) ^ " to live:\n" ^ op ^ desc) |
|
| 37585 | 206 |
else |
207 |
NONE |
|
208 |
fun canceling_info (_, (tool', death_time, desc)) = |
|
209 |
if tool' = tool then |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
210 |
SOME ("Trying to interrupt " ^ das_wort_worker ^ " since " ^
|
| 57556 | 211 |
str_of_time (Time.- (now, death_time)) ^ ":\n" ^ op ^ desc) |
| 37585 | 212 |
else |
213 |
NONE |
|
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
214 |
val running = |
| 37585 | 215 |
case map_filter running_info active of |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
216 |
[] => ["No " ^ das_wort_worker ^ "s running."] |
| 57556 | 217 |
| ss => "Running " ^ das_wort_worker ^ "s" :: ss |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
218 |
val interrupting = |
| 37585 | 219 |
case map_filter canceling_info canceling of |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
220 |
[] => [] |
| 57556 | 221 |
| ss => "Interrupting " ^ das_wort_worker ^ "s" :: ss |
| 58843 | 222 |
in writeln (space_implode "\n\n" (running @ interrupting)) end |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
223 |
|
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
224 |
fun thread_messages tool das_wort_worker opt_limit = |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
225 |
let |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
226 |
val limit = the_default message_display_limit opt_limit |
| 37585 | 227 |
val tool_store = Synchronized.value global_state |
228 |
|> #store |> filter (curry (op =) tool o fst) |
|
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
229 |
val header = |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
41042
diff
changeset
|
230 |
"Recent " ^ das_wort_worker ^ " messages" ^ |
| 37585 | 231 |
(if length tool_store <= limit then ":" |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
232 |
else " (" ^ string_of_int limit ^ " displayed):")
|
|
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
47945
diff
changeset
|
233 |
val ss = tool_store |> chop limit |> #1 |> map (op ^ o snd) |
| 58843 | 234 |
in List.app writeln (header :: maps break_into_chunks ss) end |
|
37583
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
235 |
|
|
9ce2451647d5
factored non-ATP specific code from "ATP_Manager" out, so that it can be reused for the LEO-II integration
blanchet
parents:
diff
changeset
|
236 |
end; |