3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +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>
public Context()
: base()
{
lock (creation_lock)
{
m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero);
InitContext();
}
}
/// <summary>
/// Constructor.
@ -64,6 +67,8 @@ namespace Microsoft.Z3
{
Contract.Requires(settings != null);
lock (creation_lock)
{
IntPtr cfg = Native.Z3_mk_config();
foreach (KeyValuePair<string, string> kv in settings)
Native.Z3_set_param_value(cfg, kv.Key, kv.Value);
@ -71,6 +76,7 @@ namespace Microsoft.Z3
Native.Z3_del_config(cfg);
InitContext();
}
}
#endregion
#region Symbols
@ -4381,6 +4387,7 @@ namespace Microsoft.Z3
#region Internal
internal IntPtr m_ctx = IntPtr.Zero;
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 void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode)

View file

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

View file

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