18
18
import java .util .concurrent .atomic .AtomicBoolean ;
19
19
import java .util .concurrent .locks .Lock ;
20
20
21
+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
21
22
import org .truffleruby .RubyContext ;
22
23
import org .truffleruby .RubyLanguage ;
23
24
import org .truffleruby .core .InterruptMode ;
40
41
41
42
public class RubyThread extends RubyDynamicObject implements ObjectGraphNode {
42
43
44
+ // All fields are explicitly initialized in the constructor to make the ordering clear
43
45
public final ThreadLocalGlobals threadLocalGlobals ;
44
46
public volatile InterruptMode interruptMode ;
45
47
public volatile ThreadStatus status ;
@@ -59,8 +61,7 @@ public class RubyThread extends RubyDynamicObject implements ObjectGraphNode {
59
61
public final AtomicBoolean wakeUp ;
60
62
volatile int priority ;
61
63
public ThreadLocalBuffer ioBuffer ;
62
- // Needs to be a thread-safe queue because multiple Fibers of the same Thread might enqueue concurrently
63
- public final Queue <SafepointAction > pendingSafepointActions = new LinkedBlockingQueue <>();
64
+ public final Queue <SafepointAction > pendingSafepointActions ;
64
65
Object threadGroup ;
65
66
String sourceLocation ;
66
67
Object name ;
@@ -97,6 +98,8 @@ public RubyThread(
97
98
this .wakeUp = new AtomicBoolean (false );
98
99
this .priority = Thread .NORM_PRIORITY ;
99
100
this .ioBuffer = ThreadLocalBuffer .NULL_BUFFER ;
101
+ // Needs to be a thread-safe queue because multiple Fibers of the same Thread might enqueue concurrently
102
+ this .pendingSafepointActions = newLinkedBlockingQueue ();
100
103
this .threadGroup = threadGroup ;
101
104
this .sourceLocation = sourceLocation ;
102
105
this .name = Nil .INSTANCE ;
@@ -110,4 +113,9 @@ public void getAdjacentObjects(Set<Object> reachable) {
110
113
ObjectGraph .addProperty (reachable , name );
111
114
}
112
115
116
+ @ TruffleBoundary
117
+ private static LinkedBlockingQueue <SafepointAction > newLinkedBlockingQueue () {
118
+ return new LinkedBlockingQueue <>();
119
+ }
120
+
113
121
}
0 commit comments