3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-13 09:26:15 +00:00

Re-added context creation locks in the Java API. Relates to #819.

This commit is contained in:
Christoph M. Wintersteiger 2016-12-01 23:16:15 +00:00
parent dedae29300
commit f1a704484b

View file

@ -31,13 +31,17 @@ public class Context implements AutoCloseable {
static final Object creation_lock = new Object(); static final Object creation_lock = new Object();
public Context () { public Context () {
m_ctx = Native.mkContextRc(0); synchronized (creation_lock) {
init(); m_ctx = Native.mkContextRc(0);
init();
}
} }
protected Context (long m_ctx) { protected Context (long m_ctx) {
this.m_ctx = m_ctx; synchronized (creation_lock) {
init(); this.m_ctx = m_ctx;
init();
}
} }
@ -59,13 +63,15 @@ public class Context implements AutoCloseable {
* module parameters. For this purpose we should now use {@code Global.setParameter} * module parameters. For this purpose we should now use {@code Global.setParameter}
**/ **/
public Context(Map<String, String> settings) { public Context(Map<String, String> settings) {
long cfg = Native.mkConfig(); synchronized (creation_lock) {
for (Map.Entry<String, String> kv : settings.entrySet()) { long cfg = Native.mkConfig();
Native.setParamValue(cfg, kv.getKey(), kv.getValue()); for (Map.Entry<String, String> kv : settings.entrySet()) {
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
}
m_ctx = Native.mkContextRc(cfg);
Native.delConfig(cfg);
init();
} }
m_ctx = Native.mkContextRc(cfg);
Native.delConfig(cfg);
init();
} }
private void init() { private void init() {
@ -4038,6 +4044,8 @@ public class Context implements AutoCloseable {
m_realSort = null; m_realSort = null;
m_stringSort = null; m_stringSort = null;
Native.delContext(m_ctx); synchronized (creation_lock) {
Native.delContext(m_ctx);
}
} }
} }