Skip to content

Commit 439a0ca

Browse files
committed
Set rubyManagedThreads and javaThreadToRubyThread together for Ruby Threads
1 parent 55970cf commit 439a0ca

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private Thread createFiberJavaThread(Runnable runnable) {
169169
return thread;
170170
}
171171

172-
private Thread createJavaThread(Runnable runnable, RubyFiber fiber) {
172+
private Thread createJavaThread(Runnable runnable, RubyThread rubyThread) {
173173
if (context.getOptions().SINGLE_THREADED) {
174174
throw new RaiseException(
175175
context,
@@ -182,7 +182,8 @@ private Thread createJavaThread(Runnable runnable, RubyFiber fiber) {
182182

183183
final Thread thread = context.getEnv().createThread(runnable);
184184
rubyManagedThreads.add(thread); // need to be set before initializeThread()
185-
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler(fiber));
185+
javaThreadToRubyThread.put(thread, rubyThread); // need to be set before initializeThread()
186+
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler(rubyThread.getRootFiber()));
186187
return thread;
187188
}
188189

@@ -289,7 +290,7 @@ public void initialize(RubyThread rubyThread, Node currentNode, String info, Str
289290
rubyThread.sourceLocation = info;
290291
final RubyFiber rootFiber = rubyThread.getRootFiber();
291292

292-
final Thread thread = createJavaThread(() -> threadMain(rubyThread, currentNode, task), rootFiber);
293+
final Thread thread = createJavaThread(() -> threadMain(rubyThread, currentNode, task), rubyThread);
293294
thread.setName(NAME_PREFIX + " id=" + thread.getId() + " from " + info);
294295
rubyThread.thread = thread;
295296
javaThreadToRubyThread.put(thread, rubyThread);

0 commit comments

Comments
 (0)