sonic-pi

https://github.com/sonic-pi-net/sonic-pi

C++

Code. Music. Live.

ThreadSafe::Util::Volatile#attr_volatile

Provides +volatile+ (in the JVM's sense) attribute accessors implemented atop of the +AtomicReference+s.
Usage:
  class Foo
    extend ThreadSafe::Util::Volatile
    attr_volatile :foo, :bar

    def initialize(bar)
      super() # must super() into parent initializers before using the volatile attribute accessors
      self.bar = bar
    end

    def hello
      my_foo = foo # volatile read
      self.foo = 1 # volatile write
      cas_foo(1, 2) # => true | a strong CAS
    end
  end

Source | Google | Stack overflow

Edit

git clone [email protected]:sonic-pi-net/sonic-pi.git

cd sonic-pi

open app/server/ruby/vendor/thread_safe/lib/thread_safe/util/volatile.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-ThreadSafe--Util--Volatile-attr_volatile-for-pr


# Commit to git

git add app/server/ruby/vendor/thread_safe/lib/thread_safe/util/volatile.rbgit commit -m "better docs for ThreadSafe::Util::Volatile#attr_volatile"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-ThreadSafe--Util--Volatile-attr_volatile-for-pr

hub pull-request


# Celebrate!