summaryrefslogtreecommitdiff
path: root/lib/thwait.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thwait.rb')
-rw-r--r--lib/thwait.rb88
1 files changed, 31 insertions, 57 deletions
diff --git a/lib/thwait.rb b/lib/thwait.rb
index 84ba2c8749..d3b329911f 100644
--- a/lib/thwait.rb
+++ b/lib/thwait.rb
@@ -1,38 +1,39 @@
#
-# thwait.rb - ����å�Ʊ�����饹
+# thwait.rb - thread synchronization class
# $Release Version: 0.9 $
# $Revision: 1.3 $
# $Date: 1998/06/26 03:19:34 $
# by Keiju ISHITSUKA(Nihpon Rational Software Co.,Ltd.)
#
# --
-# ��ǽ:
-# ʣ���Υ���åɤ�ؤ������Υ���åɤ���λ����ޤ�wait���뵡ǽ����
-# ������.
+# 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"
@@ -45,14 +46,6 @@ class ThreadsWait
def_exception("ErrNoWaitingThread", "No threads for waiting.")
def_exception("ErrNoFinshedThread", "No finished threads.")
- # class mthods
- # all_waits
-
- #
- # ���ꤷ������åɤ����ƽ�λ����ޤ��Ԥ�. ���ƥ졼���Ȥ��ƸƤФ���
- # ���ꤷ������åɤ���λ����Ȥ��ν�λ��������åɤ�����Ȥ��ƥ��ƥ졼
- # ����ƤӽФ�.
- #
def ThreadsWait.all_waits(*threads)
tw = ThreadsWait.new(*threads)
if iterator?
@@ -65,12 +58,6 @@ class ThreadsWait
end
end
- # initialize and terminating:
- # initialize
-
- #
- # �����. �Ԥĥ���åɤλ��꤬�Ǥ���.
- #
def initialize(*threads)
@threads = []
@wait_queue = Queue.new
@@ -78,24 +65,19 @@ class ThreadsWait
end
# accessing
- # threads
-
- # �Ԥ�����åɤΰ������֤�.
+ # threads - list threads to be synchronized
attr :threads
# testing
# empty?
# finished?
- #
-
- #
- # �Ԥ�����åɤ�¸�ߤ��뤫�ɤ������֤�.
+
+ # is there any thread to be synchronized.
def empty?
@threads.empty?
end
- #
- # ���Ǥ˽�λ��������åɤ����뤫�ɤ����֤�
+ # is there already terminated thread.
def finished?
!@wait_queue.empty?
end
@@ -106,18 +88,13 @@ class ThreadsWait
# next_wait
# all_wait
- #
- # �ԤäƤ��륹��åɤ��ɲä�. �����줫�Υ���åɤ�1�Ľ�λ����ޤ���
- # ���ˤϤ���.
- #
+ # adds thread(s) to join, waits for any of waiting threads to terminate.
def join(*threads)
join_nowait(*threads)
next_wait
end
- #
- # �ԤäƤ��륹��åɤ��ɲä���. �Ԥ��ˤ�����ʤ�.
- #
+ # adds thread(s) to join, no wait.
def join_nowait(*threads)
@threads.concat threads
for th in threads
@@ -128,12 +105,10 @@ class ThreadsWait
end
end
- #
- # �����줫�Υ���åɤ���λ����ޤ��Ԥ��ˤϤ���.
- # �ԤĤ٤�����åɤ��ʤ����, �㳰ErrNoWaitingThread���֤�.
- # nonnlock�����λ��ˤ�, nonblocking��Ĵ�٤�. ¸�ߤ��ʤ����, �㳰
- # ErrNoFinishedThread���֤�.
- #
+ # waits for any of waiting threads to terminate
+ # if there is no thread to wait, raises ErrNoWaitingThread.
+ # if `nonblock' is true, and there is no terminated thread,
+ # raises ErrNoFinishedThread.
def next_wait(nonblock = nil)
ThreadsWait.fail ErrNoWaitingThread if @threads.empty?
begin
@@ -144,10 +119,9 @@ class ThreadsWait
end
end
- #
- # ���ƤΥ���åɤ���λ����ޤ��Ԥ�. ���ƥ졼���Ȥ��ƸƤФ줿����, ��
- # ��åɤ���λ�����٤�, ���ƥ졼����ƤӽФ�.
- #
+ # waits until all of specified threads are terminated.
+ # if a block is supplied for the method, evaluates it for
+ # each thread termination.
def all_waits
until @threads.empty?
th = next_wait