Skip to content
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

Allow properties to be accessed even when the object is moved to another Ractor #29

Merged
merged 3 commits into from
Aug 20, 2021

Conversation

rm155
Copy link
Contributor

@rm155 rm155 commented Aug 18, 2021

By having the methods defined using shareable Procs, objects that are moved into another Ractor can still use these methods.

Copy link
Member

@marcandre marcandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely.
Two things:

  • could you please use ::Ractor instead of Ractor?
  • could you add a test?

@rm155
Copy link
Contributor Author

rm155 commented Aug 19, 2021

Absolutely.
Two things:

* could you please use `::Ractor` instead of `Ractor`?

* could you add a test?

I have made the additions as you suggested. Thanks!

@rm155 rm155 requested a review from marcandre August 20, 2021 02:52
@marcandre marcandre merged commit d85639f into ruby:master Aug 20, 2021
@marcandre
Copy link
Member

Great, thank you!
I will release an updated version of ostruct soon

@rm155
Copy link
Contributor Author

rm155 commented Aug 20, 2021

Great, thank you!
I will release an updated version of ostruct soon

Thanks!

matzbot pushed a commit to ruby/ruby that referenced this pull request Sep 28, 2021
setter_proc = Proc.new {|x| @table[name] = x}
if defined?(::Ractor)
::Ractor.make_shareable(getter_proc)
::Ractor.make_shareable(setter_proc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this would have the side effect of freezing the OpenStruct instance and @table but actually it does not, which is a CRuby bug: https://bugs.ruby-lang.org/issues/18243
A Ractor should never be able to mutate objects of another Ractor directly of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants