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

Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread #22630

Merged
merged 3 commits into from Dec 17, 2015

Conversation

dhh
Copy link
Member

@dhh dhh commented Dec 17, 2015

Implementation of #19693.

dhh added a commit that referenced this pull request Dec 17, 2015
Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread
@dhh dhh merged commit bb4a9e2 into master Dec 17, 2015
@dhh dhh deleted the attribute-accessors-per-thread branch December 17, 2015 15:00
raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
def self.#{sym}=(obj)
Thread.current[:"attr_#{name}_#{sym}"] = obj
Copy link
Member

Choose a reason for hiding this comment

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

I think you want to use thread_variable_get here

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice. Didn't even see those had been added. Using those instead.

Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure we don't want those. The fiber methods got the short name because they're the ones that people actually want 99% of the time... if you're not doing something very particular, what you really want is a "current-execution-stack-local" variable, and that's what fiber-locals give you.

As I confusingly mis-stated [and then corrected] around #19693 (comment), our existing internal usage is in PerThreadRegistry, which is actually per-fiber.

So, I think 301f438 should be reverted.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@hsgubert
Copy link

Anyone knows any reason why thread_mattr_accessor would be undefined when using jruby?
I'm having an issue with a gem I created (which depends on rails) where thread_mattr_accessor works fine when using MRI but is undefined when running with jruby.

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

Successfully merging this pull request may close these issues.

None yet

4 participants