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 3 commits Dec 17, 2015
…ing class and module variables that live per-thread
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
2 checks passed
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

This comment has been minimized.

@dhh

dhh Dec 17, 2015
Author 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.

This comment has been minimized.

@dhh

dhh Dec 18, 2015
Author Member

👍

@hsgubert
Copy link

@hsgubert 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.