Hello, everyone!
I'm too angry right now, so I'll be short :)
I need to allow simultaneous file updates (update order does not mean).
I do the following:
# Extend File class
class File
# Methods
# Open file, locking it
def File.open_locked(name, mode)
file = File.open name, mode
file.flock LOCK_EX
file.seek 0, (/^a/ =~ mode ? SEEK_END : SEEK_SET)
if block_given?
begin
yield file
ensure
file.close
end
else
file
end
end
end
Then I use open_locked in this way:
File.open_locked @@path, 'rb' do |file| @@options = Marshal.load file end
.....
File.open_locked @@path, 'wb' do |file| Marshal.dump @@options, file end
Seems right, isn't it ?
But, when running the script simultaneousle 50 times, data gots thrashed
resulting sometimes even in corrupted file!
It seems that Marshal.dump unlocks the file or whatever?
I think that this should be investigated immediately, and a solution should
be proposed to matz (I'll try to take a look at C source, but don't cont on
me too much)
Thanks for your attention
Aristarkh A Zagorodnikov