return;
}
msg_error_t rv;
- simgrid::kernel::context::try_n_catch_stoprequest(
- [&rv, &task]() { rv = MSG_task_execute(task); },
- [&env] { jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); });
+ if (not simgrid::kernel::context::StopRequest::try_n_catch([&rv, &task]() { rv = MSG_task_execute(task); })) {
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+ }
if (env->ExceptionOccurred())
return;
const char *alias = env->GetStringUTFChars(jalias, 0);
msg_error_t rv;
- simgrid::kernel::context::try_n_catch_stoprequest(
- [&rv, &task, &alias, &jtimeout]() {
+ if (not simgrid::kernel::context::StopRequest::try_n_catch([&rv, &task, &alias, &jtimeout]() {
rv = MSG_task_receive_ext(&task, alias, (double)jtimeout, /*host*/ nullptr);
- },
- [&env]() { jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed"); });
+ })) {
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+ }
env->ReleaseStringUTFChars(jalias, alias);
if (env->ExceptionOccurred())
return nullptr;
/* Destroy the global ref so that the JVM can free the stuff */
env->DeleteGlobalRef(jtask_global);
MSG_task_set_data(task, nullptr);
+ /* Don't free the C data here, to avoid a race condition with the GC also sometimes doing so.
+ * A rare memleak is seen as preferable to a rare "free(): invalid pointer" failure that
+ * proves really hard to debug.
+ */
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_dsend(JNIEnv * env, jobject jtask, jstring jalias)