@@ -121,10 +121,12 @@ public IRubyObject ensureIvarVisibilityBang(ThreadContext context) {
121
121
@ JRubyMethod (name = "instance_variable_get_volatile" , visibility = Visibility .PROTECTED )
122
122
public IRubyObject instanceVariableGetVolatile (ThreadContext context , IRubyObject name ) {
123
123
if (UnsafeHolder .U == null ) {
124
+ // TODO: Possibly dangerous, there may be a deadlock on the this
124
125
synchronized (this ) {
125
126
return instance_variable_get (context , name );
126
127
}
127
128
} else if (UnsafeHolder .SUPPORTS_FENCES ) {
129
+ // ensure we see latest value
128
130
UnsafeHolder .loadFence ();
129
131
return instance_variable_get (context , name );
130
132
} else {
@@ -136,11 +138,13 @@ public IRubyObject instanceVariableGetVolatile(ThreadContext context, IRubyObjec
136
138
@ JRubyMethod (name = "instance_variable_set_volatile" , visibility = Visibility .PROTECTED )
137
139
public IRubyObject InstanceVariableSetVolatile (ThreadContext context , IRubyObject name , IRubyObject value ) {
138
140
if (UnsafeHolder .U == null ) {
141
+ // TODO: Possibly dangerous, there may be a deadlock on the this
139
142
synchronized (this ) {
140
143
return instance_variable_set (name , value );
141
144
}
142
145
} else if (UnsafeHolder .SUPPORTS_FENCES ) {
143
- IRubyObject result = instance_variable_set (name , value );
146
+ final IRubyObject result = instance_variable_set (name , value );
147
+ // ensure we make latest value visible
144
148
UnsafeHolder .storeFence ();
145
149
return result ;
146
150
} else {
0 commit comments