Project

General

Profile

Bug #2543 ยป thwait_update_rdoc.diff

rogerdpack (Roger Pack), 01/01/2010 06:19 AM

View differences:

thwait.rb (working copy)
# $Release Version: 0.9 $
# $Revision: 1.3 $
# by Keiju ISHITSUKA(Nihpon Rational Software Co.,Ltd.)
#
# --
# feature:
# provides synchronization for multiple threads.
#
# class methods:
# * ThreadsWait.all_waits(thread1,...)
# waits until all of specified threads are terminated.
# if a block is supplied for the method, evaluates it for
# each thread termination.
# * th = ThreadsWait.new(thread1,...)
# creates synchronization object, specifying thread(s) to wait.
#
# methods:
# * th.threads
# list threads to be synchronized
# * th.empty?
# is there any thread to be synchronized.
# * th.finished?
# is there already terminated thread.
# * th.join(thread1,...)
# wait for specified thread(s).
# * th.join_nowait(threa1,...)
# specifies thread(s) to wait. non-blocking.
# * th.next_wait
# waits until any of specified threads is terminated.
# * th.all_waits
# waits until all of specified threads are terminated.
# if a block is supplied for the method, evaluates it for
# each thread termination.
#
require "thread.rb"
require "e2mmap.rb"
......
# STDERR.puts "Thread #{t} has terminated."
# end
#
#
# th = ThreadsWait.new(thread1,...)
# th.next_wait # next one to be done
#
#
class ThreadsWait
RCS_ID='-$Id: thwait.rb,v 1.3 1998/06/26 03:19:34 keiju Exp keiju $-'
......
#
# Waits until all specified threads have terminated. If a block is provided,
# it is executed for each thread termination.
# it is executed for each thread as they terminate.
#
def ThreadsWait.all_waits(*threads) # :yield: thread
tw = ThreadsWait.new(*threads)
......
join_nowait(*threads) unless threads.empty?
end
# Returns the array of threads in the wait queue.
# Returns the array of threads that have not terminated yet.
attr :threads
#
# Returns +true+ if there are no threads to be synchronized.
# Returns +true+ if there are no threads in the pool still running.
#
def empty?
@threads.empty?
end
#
# Returns +true+ if any thread has terminated.
# Returns +true+ if any thread has terminated and is ready to be collected.
#
def finished?
!@wait_queue.empty?
    (1-1/1)