In article <430DFCD4.6000405 / path.berkeley.edu>,
  Joel VanderWerf <vjoel / path.berkeley.edu> writes:

> I *love* ruby threads. Still, I wish ruby's thread scheduler would
> handle more types of blocking than select can handle, such as waiting
> for a file lock.

File#flock works well since Ruby 1.8.2.  It blocks only the calling
thread.  It doesn't block other threads.

% ruby-1.8.2 -ve '
f1 = open("z", "w")
f1.flock(File::LOCK_EX)
t = Thread.new {
  f2 = open("z", "w")
  p :f2_lock_start
  f2.flock(File::LOCK_EX)
  p :f2_lock_end
}
3.times {|i| p i; sleep 1 }
f1.flock(File::LOCK_UN)
t.join
'
ruby 1.8.2 (2004-12-25) [i686-linux]
:f2_lock_start
0
1
2
:f2_lock_end
-- 
Tanaka Akira