Hello everybody,
Sorry if this question was asked before.
But do there is some extensive documentation and other examples
available for sync.rb and monitor.rb (in the ruby/lib) ?
Thanks in advance
yannick
Hello everybody,
Sorry if this question was asked before.
But do there is some extensive documentation and other examples
available for sync.rb and monitor.rb (in the ruby/lib) ?
Thanks in advance
yannick
From monitor.rb rd doc:
monitor.rb
This library is distributed under the terms of the Ruby license. You
can freely distribute/modify this library.
example
This is a simple example.
require ‘monitor.rb’
buf =
buf.extend(MonitorMixin)
empty_cond = buf.new_cond
Thread.start do
loop do
buf.synchronize do
empty_cond.wait_while { buf.empty? }
print buf.shift
end
end
end
while line = ARGF.gets
buf.synchronize do
buf.push(line)
empty_cond.signal
end
end
The consumer thread waits for the producer thread to push a line to buf
while buf.empty?, and the producer thread (main thread) reads a line
from ARGF and push it to buf, then call empty_cond.signal.
-rich
Copyright (C) 2001 Shugo Maeda shugo@ruby-lang.org
On Friday, February 14, 2003, at 01:31 PM, yannick wrote:
Hello everybody,
Sorry if this question was asked before.
But do there is some extensive documentation and other examples
available for sync.rb and monitor.rb (in the ruby/lib) ?Thanks in advance
yannick