3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 21:38:44 +00:00

Bugfix for concurrent Context creation in Java and .NET.

Relates to #205 #245
This commit is contained in:
Christoph M. Wintersteiger 2015-10-14 13:58:51 +01:00
parent 2d2ec38541
commit 24532474a0
3 changed files with 44 additions and 26 deletions

View file

@ -36,10 +36,13 @@ namespace Microsoft.Z3
/// </summary> /// </summary>
public Context() public Context()
: base() : base()
{
lock (creation_lock)
{ {
m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero); m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero);
InitContext(); InitContext();
} }
}
/// <summary> /// <summary>
/// Constructor. /// Constructor.
@ -64,6 +67,8 @@ namespace Microsoft.Z3
{ {
Contract.Requires(settings != null); Contract.Requires(settings != null);
lock (creation_lock)
{
IntPtr cfg = Native.Z3_mk_config(); IntPtr cfg = Native.Z3_mk_config();
foreach (KeyValuePair<string, string> kv in settings) foreach (KeyValuePair<string, string> kv in settings)
Native.Z3_set_param_value(cfg, kv.Key, kv.Value); Native.Z3_set_param_value(cfg, kv.Key, kv.Value);
@ -71,6 +76,7 @@ namespace Microsoft.Z3
Native.Z3_del_config(cfg); Native.Z3_del_config(cfg);
InitContext(); InitContext();
} }
}
#endregion #endregion
#region Symbols #region Symbols
@ -4381,6 +4387,7 @@ namespace Microsoft.Z3
#region Internal #region Internal
internal IntPtr m_ctx = IntPtr.Zero; internal IntPtr m_ctx = IntPtr.Zero;
internal Native.Z3_error_handler m_n_err_handler = null; internal Native.Z3_error_handler m_n_err_handler = null;
internal static Object creation_lock = new Object();
internal IntPtr nCtx { get { return m_ctx; } } internal IntPtr nCtx { get { return m_ctx; } }
internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode)

View file

@ -32,9 +32,11 @@ public class Context extends IDisposable
public Context() public Context()
{ {
super(); super();
synchronized (creation_lock) {
m_ctx = Native.mkContextRc(0); m_ctx = Native.mkContextRc(0);
initContext(); initContext();
} }
}
/** /**
* Constructor. * Constructor.
@ -56,6 +58,7 @@ public class Context extends IDisposable
public Context(Map<String, String> settings) public Context(Map<String, String> settings)
{ {
super(); super();
synchronized (creation_lock) {
long cfg = Native.mkConfig(); long cfg = Native.mkConfig();
for (Map.Entry<String, String> kv : settings.entrySet()) for (Map.Entry<String, String> kv : settings.entrySet())
Native.setParamValue(cfg, kv.getKey(), kv.getValue()); Native.setParamValue(cfg, kv.getKey(), kv.getValue());
@ -63,6 +66,7 @@ public class Context extends IDisposable
Native.delConfig(cfg); Native.delConfig(cfg);
initContext(); initContext();
} }
}
/** /**
* Creates a new symbol using an integer. * Creates a new symbol using an integer.
@ -3638,7 +3642,8 @@ public class Context extends IDisposable
Native.updateParamValue(nCtx(), id, value); Native.updateParamValue(nCtx(), id, value);
} }
long m_ctx = 0; protected long m_ctx = 0;
protected static Object creation_lock = new Object();
long nCtx() long nCtx()
{ {

View file

@ -35,9 +35,12 @@ public class InterpolationContext extends Context
**/ **/
public InterpolationContext() public InterpolationContext()
{ {
super();
synchronized(creation_lock) {
m_ctx = Native.mkInterpolationContext(0); m_ctx = Native.mkInterpolationContext(0);
initContext(); initContext();
} }
}
/** /**
* Constructor. * Constructor.
@ -48,6 +51,8 @@ public class InterpolationContext extends Context
**/ **/
public InterpolationContext(Map<String, String> settings) public InterpolationContext(Map<String, String> settings)
{ {
super();
synchronized(creation_lock) {
long cfg = Native.mkConfig(); long cfg = Native.mkConfig();
for (Map.Entry<String, String> kv : settings.entrySet()) for (Map.Entry<String, String> kv : settings.entrySet())
Native.setParamValue(cfg, kv.getKey(), kv.getValue()); Native.setParamValue(cfg, kv.getKey(), kv.getValue());
@ -55,6 +60,7 @@ public class InterpolationContext extends Context
Native.delConfig(cfg); Native.delConfig(cfg);
initContext(); initContext();
} }
}
/** /**
* Create an expression that marks a formula position for interpolation. * Create an expression that marks a formula position for interpolation.