I would like to execute some atomicity methods with Ruby, according to http://en.wikipedia.org/wiki/Atomicity_(database_systems)
For example, if I have:
a = 30 b = 75
I would like to do something like:
atomic_operation do a += 10 b -= 39 end
Is there a built-in module in Ruby 1.9 that allows this process? If possible, I would like to do this without using a plugin. Many thanks!
, . , , , ( / ) .
Ruby, , Ruby Mutex ConditionVariable, . ( : http://ruby-doc.org/docs/ProgrammingRuby/html/tut_threads.html)
Mutex 1.9 ( require('thread') 1.8) .
require('thread')
# Typically defined in the object initializer @lock = Mutex.new # Then in your code @lock.synchronize do a += 10 b -= 39 end
, , Mutex #, .
: http://rubydoc.info/stdlib/core/1.9.2/Mutex
, , .
Rails, transaction ActiveRecord.
transaction
Account.transaction do @alice.withdraw!(100) @bob.deposit!(100) end
Rails , . Rails, , .
, - . STM, JRuby ( , ).
Ruby atomic. http://github.com/saivenkat/ruby-atomic. CAS MRI. , . Transactional Memory MRI, CAS :)
P.SStackoverflow , . , Codehaus STM JRuby
-
Transaction Simple?
,
http://rubyforge.org/projects/trans-simple