Skip to content
Snippets Groups Projects
Commit 554ff933 authored by Florian Angerer's avatar Florian Angerer
Browse files

Using AtomicInteger for thread count.

parent 2724640f
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,7 @@ public class FastRContext {
private static void handleSharedContexts(ContextKind contextKind) {
if (contextKind == ContextKind.SHARE_ALL) {
RContext current = RContext.getInstance();
if (EvalThread.threads.size() == 0 && (current.isInitial() || current.getKind() == ContextKind.SHARE_PARENT_RW)) {
if (EvalThread.threadCnt.get() == 0 && (current.isInitial() || current.getKind() == ContextKind.SHARE_PARENT_RW)) {
ContextInfo.resetMultiSlotIndexGenerator();
} else {
throw RError.error(RError.NO_CALLER, RError.Message.GENERIC, "Shared contexts can be created only if no other child contexts exist");
......
......@@ -31,6 +31,7 @@ import java.util.TimeZone;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
......@@ -228,10 +229,14 @@ public final class RContext extends com.oracle.truffle.api.ExecutionContext impl
public static final Map<Integer, Thread> threads = new ConcurrentHashMap<>();
/** We use a separate counter for threads since ConcurrentHashMap.size() is not reliable. */
public static final AtomicInteger threadCnt = new AtomicInteger(0);
public EvalThread(ContextInfo info, Source source) {
super(null);
this.info = info;
this.source = source;
threadCnt.incrementAndGet();
threads.put(info.getId(), this);
}
......@@ -249,6 +254,7 @@ public final class RContext extends com.oracle.truffle.api.ExecutionContext impl
} finally {
vm.dispose();
threads.remove(info.getId());
threadCnt.decrementAndGet();
}
}
......
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