Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:41:44+00:00 2026-06-15T10:41:44+00:00

For instance, methods such as: class MyClass self.perform(id) hash = doSomething(id) doMoreStuff(hash) return hash

  • 0

For instance, methods such as:

class MyClass
  self.perform(id)
    hash = doSomething(id)
    doMoreStuff(hash)
    return hash
  end
end

My concern is if I have multiple threads calling MyClass.perform(). Could the object hash be potentially overwritten by another thread? In other words, Thread 1 calls doSomething and gets a hash returned of {1 => 1}. But right afterwards Thread 2 calls doSomething and gets a hash of {2 => 2}. What happens now? Does Thread 1’s hash change to {2 => 2}?

Or does each thread work on its own hash that can never be touched by other threads? Assume doSomething and doMoreStuff are already thread-safe.

If it matters, I am using Rails 3.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:41:46+00:00Added an answer on June 15, 2026 at 10:41 am

    The local variables, such as your hash, are local to the particular invocation of the surrounding method. If two threads end up calling perform at the same time, then each call will get its own execution context and those won’t overlap unless there are shared resources involved: instance variables (@hash), class variables (@@hash), globals ($hash), … can cause concurrency problems. There’s nothing to worry about thread-wise with something simple like your perform.

    However, if perform was creating threads and you ended up with closures inside perform, then you could end up with several threads referencing the same local variables captured through the closures. So you do have to be careful about scope issues when you create threads but you don’t have to worry about it when dealing with simple methods that only work with local variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing class with many instance methods. I'd like to encapsulate (or
I have a non-static C# class with some instance methods, which I need to
Let's say we have such a class: class MyClass { public string SomeValue {
With the [attribute] notation I can attach custom attributes to class instance methods. But
What's the difference between a class method and an instance method? Are instance methods
Is using an instance of a class to access static methods considered bad practice?
A class is composed normally of member variables & methods. When we create instance
I have a Python class and its methods are partially covered by unit tests
MyClass objects have a, b, and c instance variables (forgive my vague abstractions). Additionally,
I have a class like: class MyClass: Foo = 1 Bar = 2 Whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.