-
Notifications
You must be signed in to change notification settings - Fork 419
move attr_volatile into Concurrent::Synchronization::Volatile module #424
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
move attr_volatile into Concurrent::Synchronization::Volatile module #424
Conversation
Thank you for the PR. It was not very well documented, volatile variables should not be ever accessed directly, it bypasses the volatile write/read. I've updated the example. I'll have a closer look tomorrow. |
@pitr-ch yikes, you are totally right, it obviously bypasses the whole volatility system put in place here 😳 |
else | ||
warn 'Possibly unsupported Ruby implementation' | ||
MriAttrVolatile | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use same pattern as Object is using, with the Implementation intermediate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure exactly what you are suggesting: I see that in Object there is private_constant :ObjectImplementation
, but in volatile.rb
the Volatile
constant must stay public since the it the module you include, which points to the correct module implementation.
or do you mean just adding
# @!visibility private
# @!macro internal_implementation_note
to the actual module implementation, like module JRubyAttrVolatile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I did not think it through, it's a module not a class so it is not applicable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing we could do is to maybe DRY up this switch over the ruby implementations.
Looks good 👍 Please let me know when it's ready, I'll pull it and merge it with my other changes, taking care of conflicts. |
The tests that failed on the lat Travis build can be ignored with respect to this PR. Those are mine. I've been trying to clean up our tests by removing sleep statements, make them more deterministic, etc. I made changes on master that caused those failures. I believe I have them fixed on the latest master. If they continue to be a problem I'll fix them. |
@jdantonio yeah, thanks, I figured/assumed this much. I tested on jruby and mri, at the moment I have a hard time building for rbx, but I am comfortable it's ok, since the only real change is on the jruby ext. @pitr-ch so, I think it's ready, let me know if you'd like me to squash. |
@colinsurprenant Thanks! No need for squashing, I'll pull it to my changes and I'll merge it together. |
@pitr-ch What's the status of this? Any idea when it will be ready to merge? |
Sorry, I was busy lately moving. It'll be included in #421, I'll close this PR then. |
add a new
Concurrent::Synchronization::Volatile
module which can be included into any class to add theattr_volatile
class method.Example:
For this the respective
{jruby|mri|rbx}_object.rb
have been refactored into modules but the original classes were preserved and uses the new modules so not to break backward compatibility.The Java JRuby synchronization library has been refactored to also add the previous
JRubyObject
method in the newJRubyAttrVolatile
module.I believe the only risk with the Java synchronization library changes is related to having the volatile
threadContext
field used as a memory barrier to now be located at the module level and thus will be shared across the including objects using the module. I believe thehappens-before
/ memory barrier is preserved but may be less efficient than having per-object volatile field as memory barrier.I only tested on JRuby 1.7.22 and all specs are passing.