Skip to content
Snippets Groups Projects
Commit ea9a937a authored by Adam Welc's avatar Adam Welc
Browse files

Fix for a race condition on accessing RContext.lastContext .

parent a84d62a5
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ package com.oracle.truffle.r.engine;
import java.io.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import com.oracle.truffle.api.vm.*;
......@@ -55,23 +56,32 @@ public class RContextFactory {
RContext.initialize(new RRuntimeASTAccessImpl(), RBuiltinPackages.getInstance(), FastROptions.IgnoreVisibility);
}
private static final Semaphore createSemaphore = new Semaphore(1, true);
/**
* Create a context of given kind.
*/
public static TruffleVM create(ContextInfo info, Consumer<TruffleVM.Builder> setup) {
RContext.tempInitializingContextInfo = info;
Builder builder = TruffleVM.newVM();
if (setup != null) {
setup.accept(builder);
}
TruffleVM vm = builder.build();
try {
vm.eval(TruffleRLanguage.MIME, "invisible(1)");
} catch (IOException e) {
throw RInternalError.shouldNotReachHere(e);
createSemaphore.acquire();
RContext.tempInitializingContextInfo = info;
Builder builder = TruffleVM.newVM();
if (setup != null) {
setup.accept(builder);
}
TruffleVM vm = builder.build();
try {
vm.eval(TruffleRLanguage.MIME, "invisible(1)");
} catch (IOException e) {
createSemaphore.release();
throw RInternalError.shouldNotReachHere(e);
}
RContext.associate(vm);
createSemaphore.release();
return vm;
} catch (InterruptedException x) {
throw RError.error(RError.NO_NODE, RError.Message.GENERIC, "Error creating parallel R runtime instance");
}
RContext.associate(vm);
return vm;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment