mirror of
https://github.com/Z3Prover/z3
synced 2025-04-13 12:28:44 +00:00
Bugfix for concurrent Context creation in Java and .NET.
Relates to #205 #245
This commit is contained in:
parent
2d2ec38541
commit
24532474a0
|
@ -37,8 +37,11 @@ namespace Microsoft.Z3
|
|||
public Context()
|
||||
: base()
|
||||
{
|
||||
m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero);
|
||||
InitContext();
|
||||
lock (creation_lock)
|
||||
{
|
||||
m_ctx = Native.Z3_mk_context_rc(IntPtr.Zero);
|
||||
InitContext();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -64,12 +67,15 @@ namespace Microsoft.Z3
|
|||
{
|
||||
Contract.Requires(settings != null);
|
||||
|
||||
IntPtr cfg = Native.Z3_mk_config();
|
||||
foreach (KeyValuePair<string, string> kv in settings)
|
||||
Native.Z3_set_param_value(cfg, kv.Key, kv.Value);
|
||||
m_ctx = Native.Z3_mk_context_rc(cfg);
|
||||
Native.Z3_del_config(cfg);
|
||||
InitContext();
|
||||
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);
|
||||
m_ctx = Native.Z3_mk_context_rc(cfg);
|
||||
Native.Z3_del_config(cfg);
|
||||
InitContext();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -30,10 +30,12 @@ public class Context extends IDisposable
|
|||
* Constructor.
|
||||
**/
|
||||
public Context()
|
||||
{
|
||||
{
|
||||
super();
|
||||
m_ctx = Native.mkContextRc(0);
|
||||
initContext();
|
||||
synchronized (creation_lock) {
|
||||
m_ctx = Native.mkContextRc(0);
|
||||
initContext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,12 +58,14 @@ public class Context extends IDisposable
|
|||
public Context(Map<String, String> settings)
|
||||
{
|
||||
super();
|
||||
long cfg = Native.mkConfig();
|
||||
for (Map.Entry<String, String> kv : settings.entrySet())
|
||||
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
|
||||
m_ctx = Native.mkContextRc(cfg);
|
||||
Native.delConfig(cfg);
|
||||
initContext();
|
||||
synchronized (creation_lock) {
|
||||
long cfg = Native.mkConfig();
|
||||
for (Map.Entry<String, String> kv : settings.entrySet())
|
||||
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
|
||||
m_ctx = Native.mkContextRc(cfg);
|
||||
Native.delConfig(cfg);
|
||||
initContext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -35,8 +35,11 @@ public class InterpolationContext extends Context
|
|||
**/
|
||||
public InterpolationContext()
|
||||
{
|
||||
m_ctx = Native.mkInterpolationContext(0);
|
||||
initContext();
|
||||
super();
|
||||
synchronized(creation_lock) {
|
||||
m_ctx = Native.mkInterpolationContext(0);
|
||||
initContext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,12 +51,15 @@ public class InterpolationContext extends Context
|
|||
**/
|
||||
public InterpolationContext(Map<String, String> settings)
|
||||
{
|
||||
long cfg = Native.mkConfig();
|
||||
for (Map.Entry<String, String> kv : settings.entrySet())
|
||||
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
|
||||
m_ctx = Native.mkInterpolationContext(cfg);
|
||||
Native.delConfig(cfg);
|
||||
initContext();
|
||||
super();
|
||||
synchronized(creation_lock) {
|
||||
long cfg = Native.mkConfig();
|
||||
for (Map.Entry<String, String> kv : settings.entrySet())
|
||||
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
|
||||
m_ctx = Native.mkInterpolationContext(cfg);
|
||||
Native.delConfig(cfg);
|
||||
initContext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue