1717import java .nio .charset .StandardCharsets ;
1818import java .nio .file .Path ;
1919import java .util .Set ;
20+ import java .util .concurrent .atomic .AtomicBoolean ;
2021import java .util .function .Consumer ;
2122import java .util .logging .Level ;
2223import org .checkerframework .checker .nullness .qual .Nullable ;
@@ -46,7 +47,7 @@ public final class Z3SolverContext extends AbstractSolverContext {
4647 private final ExtraOptions extraOptions ;
4748 private final Z3FormulaCreator creator ;
4849 private final Z3FormulaManager manager ;
49- private boolean closed = false ;
50+ private final AtomicBoolean closed = new AtomicBoolean ( false ) ;
5051
5152 private static final String OPT_ENGINE_CONFIG_KEY = "optsmt_engine" ;
5253 private static final String OPT_PRIORITY_CONFIG_KEY = "priority" ;
@@ -215,7 +216,7 @@ public static synchronized Z3SolverContext create(
215216
216217 @ Override
217218 protected ProverEnvironment newProverEnvironment0 (Set <ProverOptions > options ) {
218- Preconditions .checkState (!closed , "solver context is already closed" );
219+ Preconditions .checkState (!closed . get () , "solver context is already closed" );
219220 final ImmutableMap <String , Object > solverOptions =
220221 ImmutableMap .<String , Object >builder ()
221222 .put (":random-seed" , extraOptions .randomSeed )
@@ -241,7 +242,7 @@ protected InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolatio
241242 @ Override
242243 public OptimizationProverEnvironment newOptimizationProverEnvironment0 (
243244 Set <ProverOptions > options ) {
244- Preconditions .checkState (!closed , "solver context is already closed" );
245+ Preconditions .checkState (!closed . get () , "solver context is already closed" );
245246 final ImmutableMap <String , Object > solverOptions =
246247 ImmutableMap .<String , Object >builder ()
247248 // .put(":random-seed", extraOptions.randomSeed) // not supported here
@@ -269,8 +270,7 @@ public Solvers getSolverName() {
269270
270271 @ Override
271272 public void close () {
272- if (!closed ) {
273- closed = true ;
273+ if (!closed .getAndSet (true )) {
274274 long context = creator .getEnv ();
275275 creator .forceClose ();
276276 shutdownNotifier .unregister (interruptListener );
0 commit comments