From f1a704484b56555311b52dad2ab4146a5577f257 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 1 Dec 2016 23:16:15 +0000 Subject: [PATCH] Re-added context creation locks in the Java API. Relates to #819. --- src/api/java/Context.java | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/api/java/Context.java b/src/api/java/Context.java index b7656c5da..d50968a32 100644 --- a/src/api/java/Context.java +++ b/src/api/java/Context.java @@ -31,13 +31,17 @@ public class Context implements AutoCloseable { static final Object creation_lock = new Object(); public Context () { - m_ctx = Native.mkContextRc(0); - init(); + synchronized (creation_lock) { + m_ctx = Native.mkContextRc(0); + init(); + } } protected Context (long m_ctx) { - this.m_ctx = m_ctx; - init(); + synchronized (creation_lock) { + 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} **/ public Context(Map settings) { - long cfg = Native.mkConfig(); - for (Map.Entry kv : settings.entrySet()) { - Native.setParamValue(cfg, kv.getKey(), kv.getValue()); + synchronized (creation_lock) { + long cfg = Native.mkConfig(); + for (Map.Entry 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() { @@ -4037,7 +4043,9 @@ public class Context implements AutoCloseable { m_intSort = null; m_realSort = null; m_stringSort = null; - - Native.delContext(m_ctx); + + synchronized (creation_lock) { + Native.delContext(m_ctx); + } } }