@@ -41,6 +41,7 @@ JNIEXPORT void JNICALL Java_io_github_cvc5_Solver_deletePointer(JNIEnv* env,
41
41
jobject,
42
42
jlong pointer)
43
43
{
44
+ std::lock_guard<std::mutex> guard (globalLock);
44
45
const std::vector<jobject>& refs = globalReferences[pointer];
45
46
for (jobject ref : refs)
46
47
{
@@ -2437,6 +2438,7 @@ Java_io_github_cvc5_Solver_declareOracleFun(JNIEnv* env,
2437
2438
jobject oracle)
2438
2439
{
2439
2440
CVC5_JAVA_API_TRY_CATCH_BEGIN;
2441
+ std::lock_guard<std::mutex> guard (globalLock);
2440
2442
jobject oracleReference = env->NewGlobalRef (oracle);
2441
2443
globalReferences[pointer].push_back (oracleReference);
2442
2444
Solver* solver = reinterpret_cast <Solver*>(pointer);
@@ -2446,6 +2448,13 @@ Java_io_github_cvc5_Solver_declareOracleFun(JNIEnv* env,
2446
2448
std::vector<Sort> sorts = getObjectsFromPointers<Sort>(env, sortPointers);
2447
2449
std::function<Term (std::vector<Term>)> fn =
2448
2450
[env, oracleReference](std::vector<Term> input) {
2451
+ // FIXME:
2452
+ // This is likely still broken if multiple threads are
2453
+ // used as the captured JEnv ("env") is only valid on the
2454
+ // current thread. However, the callback might come from
2455
+ // any thread that encouters a term for the oracle.
2456
+ //
2457
+ // See https://github.com/sosy-lab/java-smt/pull/345
2449
2458
Term term = applyOracle (env, oracleReference, input);
2450
2459
return term;
2451
2460
};
0 commit comments