Skip to content

Instantly share code, notes, and snippets.

@daveray
Created February 18, 2012 03:24
Show Gist options
  • Save daveray/1857189 to your computer and use it in GitHub Desktop.
Save daveray/1857189 to your computer and use it in GitHub Desktop.
dosync test
# https://github.com/daveray/familiar
require 'familiar'
class DoSyncTest
def initialize()
@my_ref = Familiar.ref 0
end
def test_threaded_refs
threads = []
4.times do |i|
threads << Thread.new do
Familiar.dosync do
Familiar.alter @my_ref, Familiar[:inc]
end
end
end
threads.each { |t| t.join }
puts "my_ref = #{@my_ref.deref}"
end
end
DoSyncTest.new.test_threaded_refs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment