RubyGems Navigation menu

atomic 1.1.2

Changes in version 1.1.2: f519385 Attempting to get description to look nice on rubygems.org. <p>atomic: An atomic reference implementation for JRuby, Rubinius, and MRI.</p> <h1>Summary</h1> <p>This library provides:</p> <ul> <li>an Atomic class that guarantees atomic updates to its contained value</li> </ul> <p>The Atomic class provides accessors for the contained “value” plus two update methods:</p> <ul> <li>update will run the provided block, passing the current value and replacing it with the block result iff the value has not been changed in the mean time. It may run the block repeatedly if there are other concurrent updates in progress.</li> <li>try_update will run the provided block, passing the current value and replacing it with the block result. If the value changes before the update can happen, it will throw Atomic::ConcurrentUpdateError.</li> </ul> <p>The atomic repository is at http://github.com/headius/ruby-atomic.</p> <h1>Usage</h1> <p>The simplest way to use “atomic” is to call the “update” or “try_update” methods.</p> <p>“try_update” and “update” both call the given block, passing the current value and using the block’s result as the new value. If the value is updated by another thread before the block completes, “try update” raises a ConcurrentUpdateError and “update” retries the block. Because “update” may call the block several times when multiple threads are all updating the same value, the block’s logic should be kept as simple as possible.</p> <p>````ruby require ‘atomic’</p> <p>my_atomic = Atomic.new(0) my_atomic.update {|v| v + 1} begin my_atomic.try_update {|v| v + 1} rescue Atomic::ConcurrentUpdateError => cue # deal with it (retry, propagate, etc) end ````</p> <p>It’s also possible to use the regular get/set operations on the Atomic, if you want to avoid the exception and respond to contended changes in some other way.</p> <p><code>ruby my_atomic = Atomic.new(0) my_atomic.value # => 0 my_atomic.value = 1 my_atomic.swap(2) # => 1 my_atomic.compare_and_swap(2, 3) # => true, updated to 3 my_atomic.compare_and_swap(2, 3) # => false, current is not 2 </code></p> <h1>Building</h1> <p>As of 1.1.0, JDK8 is required to build the atomic gem, since it attempts to use the new atomic Unsafe.getAndSetObject method only in JDK8. The resulting code should still work fine as far back as Java 5.</p>

Gemfile:
= クリップボードにコピー コピー完了!

インストール:
=

バージョン履歴:

  1. 1.1.101 - May 10, 2018 java (23KB)
  2. 1.1.101 - May 10, 2018 (17.5KB)
  3. 1.1.99 - January 26, 2015 java (23.5KB)
  4. 1.1.99 - January 26, 2015 (17.5KB)
  5. 1.1.16 - March 17, 2014 (16.5KB)
  6. 1.1.2 - April 05, 2013 (15KB)
全てのバージョンを表示(全58件)

所有者:

作者:

  • Charles Oliver Nutter, MenTaLguY, Sokolov Yura

SHA 256チェックサム:

81c5a112c9e4893954e18c50ce3ec28a711dc817c7e3e137b177f704978e3f5c

累計ダウンロード数 25,475,623

このバージョンのみ 4,010

ライセンス:

N/A

必要なRubyのバージョン: なし

リンク: