Are there any operations/methods in Ruby that are guaranteed/documented to
be atomic?
I did a quick google search, and almost everything written on atomicity in
Ruby suggest wrapping a Mutex around the operation. However, I suspect
that this approach doesn't satisfy the usual definition of atomicity,
since a signal could interrupt synchronized code. For example (taken from
Ruby Best Practices):
lock = Mutex.new
# XXX this is an example of what NOT to do inside a signal handler:
trap(:USR1) do
lock.synchronize do
# if a second SIGUSR1 arrives here, this block of code
# will fire again. Attempting Mutex#synchronize twice
# the same thread leads to a deadlock error
end
end
I understand that atomicity is less important for High Level Languages,
but for the sake of research I would like to get a canonical answer on
this matter.
No comments:
Post a Comment