-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Same class variables may return different values on different modules. #3357
Comments
The example is flawed, when run under MRI you get (because cvar lookup is based on lexical scope and block-style class_eval does not change it):
How should it work? |
Ah sorry, I've written it in a hurry, the example should be: loop do
c = Class.new; c1 = Class.new(c)
[Thread.new { c.class_variable_set :@@a, 1 },
Thread.new { c1.class_variable_set :@@a, 2 }].each(&:join)
print '.'
if c.class_variable_get(:@@a) != c1.class_variable_get(:@@a)
p c.class_variable_get(:@@a), c1.class_variable_get(:@@a)
break
end
end This one ends on JRuby 1.7.21 with printing different values. Could you reformulate your question please? I am not sure what you mean. |
Looks good now, I was just thinking out loud about implementation since it not totally trivial as the class hierarchy must be traversed while looking up class variables. |
This also happens in 9k and Truffle. |
It could use single global lock for adding a class variable, assuming class variables are added mostly only during load time. |
It looks like the current implementation on JRuby is not fully correct. The read and write of the value uses ConcurrentHashMap so if the class-var exists it has volatile semantic, however during definition of a new class-var it appears it's not sufficiently protected so it can lead to class-vars to be created twice not sharing the value as they suppose two.
Update: broken example, please see the one bellow
see https://github.com/pitr-ch/jruby/blob/master/core/src/main/java/org/jruby/RubyModule.java#L3313-L3322
The text was updated successfully, but these errors were encountered: