-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move smartPos function to use it in Stainless + Portfolio solver fix #134
Conversation
I added a fix for epfl-lara/stainless#980 I found these links that discuss behavior changes for However I'm not used to using import scala.util._
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
object Timeout {
def findFirst[T](futures: Seq[Future[T]])(cond: T => Boolean): Option[T] = {
val p = Promise[Option[T]]()
val n = futures.length
var i = 0
for (future <- futures) {
future.onComplete((result: Try[T]) => result match {
case Success(res) if cond(res) =>
p.trySuccess(Some(res))
case _ =>
synchronized { i += 1 }
if (i == n) p.trySuccess(None)
})
}
Await.result(p.future, Duration.Inf)
}
def main(args: Array[String]): Unit = {
val times = Seq(4, 6, 10)
val futures = times.map(i =>
Future({
println("waiting",i)
Thread.sleep(i * 1000)
println("waited i",i)
i
})
)
val res = findFirst(futures)(_ == 6)
res match {
case None => println("none")
case Some(res) => println("result", res)
}
}
} |
Looks reasonable to me. You might want to use an AtomicInteger instead of the synchronized block because it's immune to thread starvation deadlocks. Also maybe add a dedicated |
Thanks I did the change. |
I moved CVC4 back to 1.8 for larabot, and added here some decoding for strings produced by CVC4 1.8, which contain characters of the form |
No description provided.