summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-08-27 03:55:54 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-08-27 03:55:54 +0000
commit707a0a946d55df772012b282c594df790371ec23 (patch)
tree84dec9dacaafa14ca3507be443a228137fea9a03 /lib
parent39ac1d7c22072f2d520738098692bdbce2f380df (diff)
1.1c3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/e2mmap.rb45
-rw-r--r--lib/finalize.rb52
-rw-r--r--lib/matrix.rb93
-rw-r--r--lib/shell.rb38
-rw-r--r--lib/shellwords.rb16
-rw-r--r--lib/telnet.rb27
-rw-r--r--lib/thwait.rb88
7 files changed, 190 insertions, 169 deletions
diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb
index fa10d485d8..bf860dc5c1 100644
--- a/lib/e2mmap.rb
+++ b/lib/e2mmap.rb
@@ -1,11 +1,22 @@
#
# e2mmap.rb - for ruby 1.1
-# $Release Version: 1.1$
-# $Revision: 1.7 $
-# $Date: 1998/05/19 04:38:33 $
+# $Release Version: 1.2$
+# $Revision: 1.8 $
+# $Date: 1998/08/19 15:22:22 $
# by Keiju ISHITSUKA
#
# --
+# Usage:
+#
+# class Foo
+# extend Exception2MassageMapper
+# def_exception :NewExceptionClass, "message..."[, superclass]
+# def_e2meggage ExistingExceptionClass, "message..."
+# ...
+# end
+#
+# Foo.Fail NewExceptionClass, arg...
+# Foo.Fail ExistingExceptionClass, arg...
#
#
if VERSION < "1.1"
@@ -13,7 +24,7 @@ if VERSION < "1.1"
else
module Exception2MessageMapper
- RCS_ID='-$Header: /home/keiju/var/src/var.lib/ruby/RCS/e2mmap.rb,v 1.7 1998/05/19 04:38:33 keiju Exp keiju $-'
+ @RCS_ID='-$Id: e2mmap.rb,v 1.8 1998/08/19 15:22:22 keiju Exp keiju $-'
E2MM = Exception2MessageMapper
@@ -29,10 +40,14 @@ else
end
# public :fail
- # alias e2mm_fail fail
+ alias fail! fail
+
+ #def fail(err = nil, *rest)
+ # super
+ #end
- def fail(err = nil, *rest)
- Exception2MessageMapper.fail Exception2MessageMapper::ErrNotRegisteredException, err.to_s
+ def Fail(err = nil, *rest)
+ Exception2MessageMapper.Fail Exception2MessageMapper::ErrNotRegisteredException, err.inspect
end
def bind(cl)
@@ -42,6 +57,22 @@ else
# err: Exception
# rest: Parameter accompanied with the exception
#
+ def self.Fail(err = nil, *rest)
+ if form = E2MM_ErrorMSG[err]
+ $! = err.new(sprintf(form, *rest))
+ $@ = caller(0) if $@.nil?
+ $@.shift
+ # e2mm_fail()
+ raise()
+# elsif self == Exception2MessageMapper
+# fail Exception2MessageMapper::ErrNotRegisteredException, err.to_s
+ else
+# print "super\n"
+ super
+ end
+ end
+
+ # 過去の互換性のため
def self.fail(err = nil, *rest)
if form = E2MM_ErrorMSG[err]
$! = err.new(sprintf(form, *rest))
diff --git a/lib/finalize.rb b/lib/finalize.rb
index acbaf0e66f..a07e67d093 100644
--- a/lib/finalize.rb
+++ b/lib/finalize.rb
@@ -11,36 +11,34 @@
#
# add(obj, dependant, method = :finalize, *opt)
# add_dependency(obj, dependant, method = :finalize, *opt)
-# 依存関係 R_method(obj, dependant) の追加
+# add dependency R_method(obj, dependant)
#
# delete(obj_or_id, dependant, method = :finalize)
# delete_dependency(obj_or_id, dependant, method = :finalize)
-# 依存関係 R_method(obj, dependant) の削除
+# delete dependency R_method(obj, dependant)
# delete_all_dependency(obj_or_id, dependant)
-# 依存関係 R_*(obj, dependant) の削除
+# delete dependency R_*(obj, dependant)
# delete_by_dependant(dependant, method = :finalize)
-# 依存関係 R_method(*, dependant) の削除
+# delete dependency R_method(*, dependant)
# delete_all_by_dependant(dependant)
-# 依存関係 R_*(*, dependant) の削除
+# delete dependency R_*(*, dependant)
# delete_all
-# 全ての依存関係の削除.
+# delete all dependency R_*(*, *)
#
# finalize(obj_or_id, dependant, method = :finalize)
# finalize_dependency(obj_or_id, dependant, method = :finalize)
-# 依存関連 R_method(obj, dependtant) で結ばれるdependantを
-# finalizeする.
+# finalize the dependant connected by dependency R_method(obj, dependtant).
# finalize_all_dependency(obj_or_id, dependant)
-# 依存関連 R_*(obj, dependtant) で結ばれるdependantをfinalizeする.
+# finalize all dependants connected by dependency R_*(obj, dependtant).
# finalize_by_dependant(dependant, method = :finalize)
-# 依存関連 R_method(*, dependtant) で結ばれるdependantをfinalizeする.
+# finalize the dependant connected by dependency R_method(*, dependtant).
# fainalize_all_by_dependant(dependant)
-# 依存関連 R_*(*, dependtant) で結ばれるdependantをfinalizeする.
+# finalize all dependants connected by dependency R_*(*, dependant).
# finalize_all
-# Finalizerに登録される全てのdependantをfinalizeする
+# finalize all dependency registered to the Finalizer.
#
# safe{..}
-# gc時にFinalizerが起動するのを止める.
-#
+# stop invoking Finalizer on GC.
#
module Finalizer
@@ -48,7 +46,7 @@ module Finalizer
# @dependency: {id => [[dependant, method, *opt], ...], ...}
- # 依存関係 R_method(obj, dependant) の追加
+ # add dependency R_method(obj, dependant)
def add_dependency(obj, dependant, method = :finalize, *opt)
ObjectSpace.call_finalizer(obj)
method = method.intern unless method.kind_of?(Integer)
@@ -61,7 +59,7 @@ module Finalizer
end
alias add add_dependency
- # 依存関係 R_method(obj, dependant) の削除
+ # delete dependency R_method(obj, dependant)
def delete_dependency(id, dependant, method = :finalize)
id = id.id unless id.kind_of?(Integer)
method = method.intern unless method.kind_of?(Integer)
@@ -75,7 +73,7 @@ module Finalizer
end
alias delete delete_dependency
- # 依存関係 R_*(obj, dependant) の削除
+ # delete dependency R_*(obj, dependant)
def delete_all_dependency(id, dependant)
id = id.id unless id.kind_of?(Integer)
method = method.intern unless method.kind_of?(Integer)
@@ -88,7 +86,7 @@ module Finalizer
end
end
- # 依存関係 R_method(*, dependant) の削除
+ # delete dependency R_method(*, dependant)
def delete_by_dependant(dependant, method = :finalize)
method = method.intern unless method.kind_of?(Integer)
for id in @dependency.keys
@@ -96,15 +94,14 @@ module Finalizer
end
end
- # 依存関係 R_*(*, dependant) の削除
+ # delete dependency R_*(*, dependant)
def delete_all_by_dependant(dependant)
for id in @dependency.keys
delete_all_dependency(id, dependant)
end
end
- # 依存関連 R_method(obj, dependtant) で結ばれるdependantをfinalizeす
- # る.
+ # finalize the depandant connected by dependency R_method(obj, dependtant)
def finalize_dependency(id, dependant, method = :finalize)
id = id.id unless id.kind_of?(Integer)
method = method.intern unless method.kind_of?(Integer)
@@ -119,7 +116,7 @@ module Finalizer
end
alias finalize finalize_dependency
- # 依存関連 R_*(obj, dependtant) で結ばれるdependantをfinalizeする.
+ # finalize all dependants connected by dependency R_*(obj, dependtant)
def finalize_all_dependency(id, dependant)
id = id.id unless id.kind_of?(Integer)
method = method.intern unless method.kind_of?(Integer)
@@ -132,7 +129,7 @@ module Finalizer
end
end
- # 依存関連 R_method(*, dependtant) で結ばれるdependantをfinalizeする.
+ # finalize the dependant connected by dependency R_method(*, dependtant)
def finalize_by_dependant(dependant, method = :finalize)
method = method.intern unless method.kind_of?(Integer)
for id in @dependency.keys
@@ -140,14 +137,14 @@ module Finalizer
end
end
- # 依存関連 R_*(*, dependtant) で結ばれるdependantをfinalizeする.
+ # finalize all dependants connected by dependency R_*(*, dependtant)
def fainalize_all_by_dependant(dependant)
for id in @dependency.keys
finalize_all_dependency(id, dependant)
end
end
- # Finalizerに登録されている全てのdependantをfinalizeする
+ # finalize all dependants registered to the Finalizer.
def finalize_all
for id, assocs in @dependency
for dependant, method, *opt in assocs
@@ -157,7 +154,7 @@ module Finalizer
end
end
- # finalize_* を安全に呼び出すためのイテレータ
+ # method to call finalize_* safely.
def safe
old_status = Thread.critical
Thread.critical = TRUE
@@ -167,7 +164,7 @@ module Finalizer
Thread.critical = old_status
end
- # ObjectSpace#add_finalizerへの登録関数
+ # registering function to ObjectSpace#add_finalizer
def final_of(id)
if assocs = @dependency.delete(id)
for dependant, method, *opt in assocs
@@ -202,4 +199,3 @@ module Finalizer
private_class_method :final_of
end
-
diff --git a/lib/matrix.rb b/lib/matrix.rb
index fcb0b29eb5..fcecbe541a 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -33,101 +33,108 @@
# Methods:
# class methods:
# Matrix.[](*rows)
-# rowsで渡された行列を生成する. rowsは配列の配列
-# Matrix[[11, 12], [21, 22]]
+# creates a matrix where `rows' indicates rows.
+# `rows' is an array of arrays,
+# e.g, Matrix[[11, 12], [21, 22]]
# Matrix.rows(rows, copy = TRUE)
-# rowsを行ベクトルの集合として行列を生成する. copy=FALSE の
-# 時はその配列をそのまま用いる.
+# creates a matrix where `rows' indicates rows.
+# if optional argument `copy' is false, use the array as
+# internal structure of the metrix without copying.
# Matrix.columns(columns)
-# rowsを列ベクトルの集合として行列を生成する.
+# creates a new matrix using `columns` as set of colums vectors.
# Matrix.diagonal(*values)
-# valuesを対角成分とした対角行列を生成する.
+# creates a matrix where `columns' indicates columns.
# Matrix.scalar(n, value)
-# valueを対角成分とするn次ののスカラー行列を生成する.
+# creates a diagonal matrix such that the diagal compornents is
+# given by `values'.
+# Matrix.scalar(n, value)
+# creates an n-by-n scalar matrix such that the diagal compornent is
+# given by `value'.
# Matrix.identity(n)
# Matrix.unit(n)
# Matrix.I(n)
-# n次の単位行列を生成する.
+# creates an n-by-n unit matrix.
# Matrix.zero(n)
-# n次の0-行列を生成する.
+# creates an n-by-n zero matrix.
# Matrix.row_vector(row)
-# rowを行ベクトルとする1-n行列を生成する. rowはVectorかArray
-# が可能.
+# creates a 1-by-n matrix such the row vector is `row'.
+# `row' is specifed as a Vector or an Array.
# Matrix.column_vector(column)
-# columnを列ベクトルとするn-1行列を生成する. rowはVectorかArray
-# が可能.
+# creates a 1-by-n matrix such that column vector is `column'.
+# `column' is specifed as a Vector or an Array.
# accessing:
# [](i, j)
-# 行列の(i, j)成分を返す.
+# returns (i,j) compornent
# row_size
-# 行数を返す.
+# returns the number of rows
# column_size
-# 列数を返す.
+# returns the number of columns
# row(i)
-# i番目の行ベクトルを返す. イテレータとして使われた時は, 行
-# ベクトルを順番にイテーレータブロックに渡す.
+# returns the i-th row vector.
+# when the block is supplied for the method, the block is iterated
+# over all row vectors.
# column(j)
-# j番目の列ベクトルを返す. 列ベクトルを順番にイテーレータブ
-# ロックに渡す.
+# returns the jth column vector.
+# when the block is supplied for the method, the block is iterated
+# over all column vectors.
# collect
# map
-# 全ての要素をイテレートしその戻り値を値とする行列を新たに生
-# 成する.
+# creates a matrix which is the result of iteration of given
+# block over all compornents.
# minor(*param)
-# マイナー行列を返す. パラメータとしては, 以下のパターンがあ
-# る:
+# returns sub matrix. parameter is specified as the following:
# 1. from_row, row_size, from_col, size_col
# 2. from_row..to_row, from_col..to_col
# TESTING:
# regular?
-# 正則かどうか?
+# Is regular?
# singular?
-# 正則ではないかどうか?
+# Is singular? i.e. Is non-regular?
# square?
-# 正方行列かどうか?
+# Is square?
# ARITHMETIC:
# *(m)
-# 乗法
+# times
# +(m)
-# 加法
+# plus
# -(m)
-# 減法
+# minus
# /(m)
# self * m.inv
# inverse
# inv
-# 逆行列
+# inverse
# **
-# 冪乗
+# power
# Matrix functions:
# determinant
# det
-# 行列式
+# returns the determinant
# rank
-# ランク
+# returns the rank
# trace
# tr
-# トレース
+# returns the trace
# transpose
# t
-# 転置行列
+# returns the transposed
# CONVERTING:
# coerce(other)
# row_vectors
-# rowベクトルの配列
+# array of row vectors
# column_vectors
-# columベクトルの配列
+# array of column vectors
# to_a
-# (2重)配列に変換
+# converts each element to Array
# to_f
-# 各要素をFloatに変換
+# converts each element to Float
# to_i
-# 各要素をIntegerに変換
+# converts each element to Integer
# to_r
-# 各要素をRationalに変換
+# converts each element to Rational
# PRINTING:
# to_s
-# 文字列としての表現
+# returns string representation
# inspect
#
# class Vector
diff --git a/lib/shell.rb b/lib/shell.rb
index a0ade9ab46..3d8dda0445 100644
--- a/lib/shell.rb
+++ b/lib/shell.rb
@@ -123,7 +123,6 @@ class Shell
end
end
- # Dir関連メソッド
def [](pattern)
Thread.critical=TRUE
back = Dir.pwd
@@ -196,7 +195,7 @@ class Shell
end
#
- # modeはpathがファイルの時だけ有効
+ # `mode' is effective iff `path' is specifying a file.
#
def open(path, mode)
path = expand_path(path)
@@ -224,7 +223,7 @@ class Shell
end
#
- # コマンド拡張
+ # command extension
# command_specs = [[command_name, [arguments,...]]]
# FILENAME* -> expand_path(filename*)
# \*FILENAME* -> filename*.collect{|fn| expand_path(fn)}.join(", ")
@@ -259,8 +258,8 @@ class Shell
end
#
- # File関連メソッド
- # open/foreach/unlinkは別定義
+ # File methods
+ # open/foreach/unlink are defined elsewhere.
#
normal_delegation_file_methods = [
["atime", ["FILENAME"]],
@@ -287,11 +286,11 @@ class Shell
normal_delegation_file_methods)
alias rm delete
- # FileTest関連メソッド
+ # FileTest method
def_commands(FileTest,
FileTest.singleton_methods.collect{|m| [m, ["FILENAME"]]})
- # ftools関連メソッド
+ # ftools methods
normal_delegation_ftools_methods = [
["syscopy", ["FILENAME_FROM", "FILENAME_TO"]],
["copy", ["FILENAME_FROM", "FILENAME_TO"]],
@@ -310,7 +309,7 @@ class Shell
alias rm_f safe_unlink
alias mkpath makedirs
- # testコマンド
+ # test function
alias top_level_test test
def test(command, file1, file2 = nil)
if file2
@@ -320,7 +319,7 @@ class Shell
end
end
- # shell拡張
+ # shell functions
def echo(*strings)
Echo.new(self, *strings)
end
@@ -342,7 +341,7 @@ class Shell
end
#
- # コマンドを検索する. もし存在しなけば例外を返す.
+ # search for command, raise exception if not found.
#
def find_system_command(command)
return command if /^\// =~ command
@@ -369,8 +368,7 @@ class Shell
end
#
- # コマンドを特異メソッドとして定義する.
- # 定義できない時は例外が発生する.
+ # define command as singleton method.
#
def def_system_command(command, path = command)
d = "
@@ -392,8 +390,7 @@ class Shell
end
#
- # コマンドをShellのメソッドとして定義する.
- # 定義できない時は例外が発生する.
+ # define command as Shell method.
#
def Shell.def_system_command(command, path = command)
d = "
@@ -415,12 +412,9 @@ class Shell
end
#
- # default_path上にのるコマンドを定義する. すでに同名のメソッドが存在
- # する時は, 定義を行なわない.
- # デフォルトでは, 全てのメソッドには接頭子"sys_"をつける.
- # メソッド名として許されないキャラクタ(英数時以外とメソッド名の
- # 先頭が数値になる場合)は, 強制的に``_''に変換する.
- # 定義エラーは無視する.
+ # defines commands on default_path. if the method is already defined,
+ # do nothing. as default, methods are prefixed by "sys_".
+ # invalid characters as method name are converted into "_".
#
def Shell.install_system_command(pre = "sys_")
defined_meth = {}
@@ -449,8 +443,8 @@ class Shell
end
#
- # Filterクラス
- # 必要なメソッド:
+ # Filter
+ # required method:
# each()
class Filter
include Enumerable
diff --git a/lib/shellwords.rb b/lib/shellwords.rb
index 9632f1222a..9154cd84c1 100644
--- a/lib/shellwords.rb
+++ b/lib/shellwords.rb
@@ -18,21 +18,19 @@ module Shellwords
while line != ''
field = ''
while TRUE
- if line.sub! /^"(([^"\\]|\\.)*)"/, '' then
+ if line.sub! /^"(([^"\\]|\\.)*)"/, '' then #"
snippet = $1
snippet.gsub! /\\(.)/, '\1'
- elsif line =~ /^"/ then
- STDOUT.print "Unmatched double quote: $_\n"
- exit
- elsif line.sub! /^'(([^'\\]|\\.)*)'/, '' then
+ elsif line =~ /^"/ then #"
+ raise ArgError, "Unmatched double quote: #{line}"
+ elsif line.sub! /^'(([^'\\]|\\.)*)'/, '' then #'
snippet = $1
snippet.gsub! /\\(.)/, '\1'
- elsif line =~ /^'/ then
- STDOUT.print "Unmatched single quote: $_\n"
- exit
+ elsif line =~ /^'/ then #'
+ raise ArgError, "Unmatched single quote: #{line}"
elsif line.sub! /^\\(.)/, '' then
snippet = $1
- elsif line.sub! /^([^\s\\'"]+)/, '' then
+ elsif line.sub! /^([^\s\\'"]+)/, '' then #'
snippet = $1
else
line.sub! /^\s+/, ''
diff --git a/lib/telnet.rb b/lib/telnet.rb
index 4e690b9aa8..ca68e1b3e5 100644
--- a/lib/telnet.rb
+++ b/lib/telnet.rb
@@ -1,8 +1,11 @@
#
# telnet.rb
-# ver0.122 1998/08/05
+# ver0.13 1998/08/25
# Wakou Aoyama <wakou@fsinet.or.jp>
#
+# ver0.13 1998/08/25
+# add print method.
+#
# ver0.122 1998/08/05
# support for HP-UX 10.20 thanks to WATANABE Tetsuya <tetsu@jpn.hp.com>
# socket.<< --> socket.write
@@ -59,6 +62,9 @@
# "Prompt" => /[$%#>] $//,
# "Timeout" => 10}){|c| print c }
#
+# == send string
+# host.print("string")
+#
# == login
# host.login("username", "password")
# host.login({"Name" => "username",
@@ -82,6 +88,17 @@
# localhost.login("username", "password"){|c| print c }
# localhost.cmd("command"){|c| print c }
# localhost.close
+#
+# == sample 2
+# checks a POP server to see if you have mail.
+#
+# pop = Telnet.new({"Host" => "your_destination_host_here",
+# "Port" => 110,
+# "Telnetmode" => FALSE,
+# "Prompt" => /^\+OK/})
+# pop.cmd("user " + "your_username_here"){|c| print c}
+# pop.cmd("pass " + "your_password_here"){|c| print c}
+# pop.cmd("list"){|c| print c}
require "socket"
require "delegate"
@@ -191,7 +208,7 @@ class Telnet < SimpleDelegator
# respond to "IAC AYT" (are you there)
str.gsub!(/([^#{IAC}])?#{IAC}#{AYT}/no){
- @sock.write("nobody here but us pigeons" + CR)
+ @sock.write("nobody here but us pigeons" + EOL)
$1
}
@@ -234,6 +251,10 @@ class Telnet < SimpleDelegator
line
end
+ def print(string)
+ @sock.write(string.gsub(/\n/, EOL) + EOL)
+ end
+
def cmd(options)
match = @options["Prompt"]
timeout = @options["Timeout"]
@@ -247,7 +268,7 @@ class Telnet < SimpleDelegator
end
select(nil, [@sock])
- @sock.write(string.gsub(/\n/, CR) + CR)
+ @sock.write(string.gsub(/\n/, EOL) + EOL)
if iterator?
waitfor({"Prompt" => match, "Timeout" => timeout}){|c| yield c }
else
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