Last active
August 25, 2016 17:34
-
-
Save amit/b9553715e01188e48b78616ca66c12b8 to your computer and use it in GitHub Desktop.
Revisions
-
amit renamed this gist
Aug 25, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
amit created this gist
Aug 25, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 }