Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
fbb3ec13
Commit
fbb3ec13
authored
12 years ago
by
Philippe Suter
Browse files
Options
Downloads
Patches
Plain Diff
Resurrected TimeoutSolver.scala
parent
2ee3511a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/solvers/TimeoutSolver.scala
+59
-0
59 additions, 0 deletions
src/main/scala/leon/solvers/TimeoutSolver.scala
with
59 additions
and
0 deletions
src/main/scala/leon/solvers/TimeoutSolver.scala
0 → 100644
+
59
−
0
View file @
fbb3ec13
package
leon
package
solvers
import
purescala.Common._
import
purescala.Definitions._
import
purescala.Trees._
import
purescala.TypeTrees._
import
scala.sys.error
class
TimeoutSolver
(
solver
:
Solver
,
timeout
:
Int
)
extends
Solver
(
solver
.
context
)
with
NaiveIncrementalSolver
{
// I'm making this an inner class to fight the temptation of using it for anything meaningful.
// We have Akka, these days, which whould be better in any respect for non-trivial things.
private
class
Timer
(
callback
:
()
=>
Unit
,
maxSecs
:
Int
)
extends
Thread
{
private
var
keepRunning
=
true
private
val
asMillis
:
Long
=
1000L
*
maxSecs
override
def
run
:
Unit
=
{
val
startTime
:
Long
=
System
.
currentTimeMillis
var
exceeded
:
Boolean
=
false
while
(!
exceeded
&&
keepRunning
)
{
if
(
asMillis
<
(
System
.
currentTimeMillis
-
startTime
))
{
exceeded
=
true
}
Thread
.
sleep
(
10
)
}
if
(
exceeded
&&
keepRunning
)
{
callback
()
}
}
def
halt
:
Unit
=
{
keepRunning
=
false
}
}
val
description
=
solver
.
description
+
", with timeout"
val
name
=
solver
.
name
+
"+to"
override
def
setProgram
(
prog
:
Program
)
:
Unit
=
{
solver
.
setProgram
(
prog
)
}
def
solve
(
expression
:
Expr
)
:
Option
[
Boolean
]
=
{
val
timer
=
new
Timer
(()
=>
solver
.
halt
,
timeout
)
timer
.
start
val
res
=
solver
.
solve
(
expression
)
timer
.
halt
res
}
override
def
init
()
{
solver
.
init
}
override
def
halt
()
{
solver
.
halt
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment