Skip to content

Instantly share code, notes, and snippets.

@amit
Last active August 25, 2016 17:34
Show Gist options
  • Select an option

  • Save amit/b9553715e01188e48b78616ca66c12b8 to your computer and use it in GitHub Desktop.

Select an option

Save amit/b9553715e01188e48b78616ca66c12b8 to your computer and use it in GitHub Desktop.

Revisions

  1. amit renamed this gist Aug 25, 2016. 1 changed file with 0 additions and 0 deletions.
  2. amit created this gist Aug 25, 2016.
    17 changes: 17 additions & 0 deletions Activerecord test of simulteneous access serialization
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    threads = []
    (0..4).each do
    threads << Thread.new {
    row = XAuth::Variable.where(name: "current_member_id").first_or_create
    row.with_lock do
    sleep(2)
    oldvalue = row.value.to_i
    newvalue = oldvalue + 1
    row.value = newvalue
    row.save!
    puts "#{Thread.current.object_id} ==> Old: #{oldvalue} , New val = #{newvalue}"
    end
    }

    end

    threads.each { |thr| thr.join }