Code Monkey home page Code Monkey logo

Comments (5)

mighe avatar mighe commented on May 16, 2024

I think the best way is something like that

  1. we should define a macro like
def atomic_attribute(name)
  # generates synchronized getter and setter
end 

this macro is different form MRI, JRuby (where we can use your code) and Rubinius

  1. in our classes
class XXX

  atomic_attribute :mutex

  def initialize
    self.mutex = Mutex.new
  end
end

from concurrent-ruby.

pitr-ch avatar pitr-ch commented on May 16, 2024

Wouldn't there be a problem that all the atomic_attributes would share a single lock?

from concurrent-ruby.

mighe avatar mighe commented on May 16, 2024

The lock will be per-instance and usually we have only few atomic_attr, everything else is guarded by the ruby lock.
My idea is only to take your code and encapsulate it into an handy higher-level idea like the atomic_attr

from concurrent-ruby.

pitr-ch avatar pitr-ch commented on May 16, 2024

Lets call it volatile_attr since this use-case does not involve CAS operations. Anyway I am not sure about this, we do not have any object using multiple locks in concurrent-ruby, so we do not need volatile_attr at this point. As a user I would also expect from volatile_attr that it won't share a single lock (even though it is per instance), it may lead to unexpected deadlocks. I think adding volatile_attr (or atomic_attr) is another issue and without the JRuby support it would be more costly than just JRuby.reference0(self).synchronized { yield }.

from concurrent-ruby.

pitr-ch avatar pitr-ch commented on May 16, 2024

will be addressed in #242

from concurrent-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.