Atomic Hamster

Because naming things is sometimes funny.

We have:

An atomic reference implementation for JRuby, Rubinius, and MRI.

Efficient, Immutable, Thread-Safe Collection classes for Ruby.

When writing threaded code, the Atomic Hamster guards and protects your shared mutable state.

require "atomic_hamster"

container = Atomic.new(Hamster.list)
iterations = 1_000

iterations.times.map do |i|
  Thread.new do
    sleep(rand)
    container.update do |list|
      list.cons(i)
    end
  end
end.map(&:join)

puts container.value.length # => 1000

Credits

All credits go to the Atomic Hamster. I did not do anything.