Great.
Thank you for good advice, Laurent.

Finally, I use the following code.

..--------------------
filename = 'sample.data'

## reader lock
File.open(filename) do |file|
  file.flock(File::LOCK_SH)
  ... operation to file ...
  #file.flock(File::LOCK_UN)   # no need
end

## writer lock
File.open(filename, 'r+') do |file|
  file.flock(File::LOCK_EX)
  ... operation to file ...
  #file.flock(File::LOCK_UN)   # no need
end
..--------------------

--
  regards,
  kwatch

Laurent Sansonetti <laurent / datarescue.be> wrote in message news:<3EAF7FAE.9030501 / datarescue.be>...
> Hello,
> 
> kwatch wrote:
> 
> > A method File#flock() is available on Windows?
> > I wonder it may be available only on *nix.
> > 
> 
> It seems that the File#flock method is weirdly implemented on Windows:
> 
> Z:\>irb --simple-prompt
>  >> f = File.open("testfile")
>  => #<File:0x2a4b030>
>  >> f.flock(File::LOCK_EX|File::LOCK_NB)
>  => 0
>  >> f.flock(File::LOCK_EX|File::LOCK_NB)
> Errno::ENOENT: No such file or directory - "testfile"
>          from (irb):3:in `flock'
>          from (irb):3
>  >>
> 
> According to pickaxe, Ruby should return 'false' for the second flock() 
> call.
> 
> Z:\>ruby -v
> ruby 1.6.8 (2002-12-24) [i586-mswin32]