From 1c05b60870d3cdeb966e6e6d694713d2e5a00820 Mon Sep 17 00:00:00 2001 From: MichalMoskal Date: Thu, 17 Feb 2011 22:15:21 +0000 Subject: Kill the solver process when ctrl-c is pressed --- Source/Provers/SMTLib/SMTLibProcess.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'Source/Provers/SMTLib/SMTLibProcess.cs') diff --git a/Source/Provers/SMTLib/SMTLibProcess.cs b/Source/Provers/SMTLib/SMTLibProcess.cs index b23fddbb..d2038d70 100644 --- a/Source/Provers/SMTLib/SMTLibProcess.cs +++ b/Source/Provers/SMTLib/SMTLibProcess.cs @@ -21,7 +21,8 @@ namespace Microsoft.Boogie.SMTLib readonly SMTLibProverOptions options; readonly Queue proverOutput = new Queue(); readonly Queue proverErrors = new Queue(); - readonly TextWriter toProver; + readonly TextWriter toProver; + ConsoleCancelEventHandler cancelEvent; public static ProcessStartInfo ComputerProcessStartInfo(string executable, string options) { @@ -39,6 +40,11 @@ namespace Microsoft.Boogie.SMTLib { this.options = options; + if (cancelEvent == null && CommandLineOptions.Clo.RunningBoogieFromCommandLine) { + cancelEvent = new ConsoleCancelEventHandler(ControlCHandler); + Console.CancelKeyPress += cancelEvent; + } + try { prover = Process.Start(psi); prover.ErrorDataReceived += prover_ErrorDataReceived; @@ -51,6 +57,14 @@ namespace Microsoft.Boogie.SMTLib } } + [NoDefaultContract] // important, since we have no idea what state the object might be in when this handler is invoked + void ControlCHandler(object o, ConsoleCancelEventArgs a) + { + if (prover != null) { + prover.Kill(); + } + } + public void Send(string cmd) { if (options.Verbosity >= 2) { @@ -257,12 +271,22 @@ namespace Microsoft.Boogie.SMTLib return proverOutput.Dequeue(); } - if (prover.HasExited) + if (prover.HasExited) { + DisposeProver(); return null; + } } } } + void DisposeProver() + { + if (cancelEvent != null) { + Console.CancelKeyPress -= cancelEvent; + cancelEvent = null; + } + } + void prover_OutputDataReceived(object sender, DataReceivedEventArgs e) { lock (this) { @@ -288,7 +312,6 @@ namespace Microsoft.Boogie.SMTLib } } #endregion - } } -- cgit v1.2.3