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

Projects
None yet
4 participants
@dhh
Member

dhh commented Dec 17, 2015

Implementation of #19693.

dhh added some commits Dec 17, 2015

Add thread_m/cattr_accessor/reader/writer suite of methods for declar…
…ing class and module variables that live per-thread

dhh added a commit that referenced this pull request Dec 17, 2015

Merge pull request #22630 from rails/attribute-accessors-per-thread
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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@dhh dhh deleted the attribute-accessors-per-thread branch Dec 17, 2015

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

This comment has been minimized.

@rafaelfranca

rafaelfranca Dec 17, 2015

Member

I think you want to use thread_variable_get here

@rafaelfranca

rafaelfranca Dec 17, 2015

Member

I think you want to use thread_variable_get here

This comment has been minimized.

@dhh

dhh Dec 17, 2015

Member

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

@dhh

dhh Dec 17, 2015

Member

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

This comment has been minimized.

@matthewd

matthewd Dec 18, 2015

Member

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.

@matthewd

matthewd Dec 18, 2015

Member

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.

This comment has been minimized.

@dhh

dhh Dec 18, 2015

Member

👍

@dhh

dhh Dec 18, 2015

Member

👍

@hsgubert

This comment has been minimized.

Show comment
Hide comment
@hsgubert

hsgubert Aug 14, 2018

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.

hsgubert commented Aug 14, 2018

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