クラス
- File (12)
-
File
:: Stat (12) - Mutex (2)
- Pathname (12)
- SignalException (24)
- Thread (120)
-
Thread
:: Mutex (10) - ThreadGroup (24)
- ThreadsWait (42)
キーワード
- <=> (12)
-
abort
_ on _ exception (12) -
abort
_ on _ exception= (12) - add (12)
-
all
_ waits (6) - ctime (12)
- empty? (6)
- enclose (12)
- exit (12)
- finished? (6)
- flock (12)
- join (6)
-
join
_ nowait (6) - kill (12)
-
next
_ wait (6) - priority (12)
- priority= (12)
- raise (12)
- signm (12)
- signo (12)
- terminate (12)
- threads (6)
- value (12)
- wakeup (12)
検索結果
先頭5件
-
ThreadGroup
# add(thread) -> self (3013.0) -
スレッド thread が属するグループを自身に変更します。
...ープを自身に変更します。
@param thread 自身に加えたいスレッドを指定します。
@raise ThreadError 自身が freeze されているか enclose されている場合に、発生します。また引数 thread が属する ThreadGroup が freeze されているか enclose......ruby]{
puts "Initial group is #{ThreadGroup::Default.list}"
# => Initial group is [#<Thread:0x4a49168 run>]
tg = ThreadGroup.new
t1 = Thread.new { sleep }
t2 = Thread.new { sleep }
puts "t1 is #{t1}" # => t1 is #<Thread:0x50bef60>
puts "t2 is #{t2}" # => t2 is #<Thread:0x50beed0>
tg.add(t1)
puts "I......nitial group now #{ThreadGroup::Default.list}"
# => Initial group now [#<Thread:0x3039168 run>, #<Thread:0x50beed0 run>]
puts "tg group now #{tg.list}"
# => tg group now [#<Thread:0x50bef60 run>]
//}... -
Pathname
# ctime -> Time (3007.0) -
File.ctime(self.to_s) を渡したものと同じです。
....ctime(self.to_s) を渡したものと同じです。
//emlist[例][ruby]{
require 'pathname'
IO.write("testfile", "test")
pathname = Pathname("testfile")
pathname.ctime # => 2019-01-14 00:39:51 +0900
sleep 1
pathname.chmod(0755)
pathname.ctime # => 2019-01-14 00:39:52 +0900
//}
@see File.ctime... -
SignalException
# signm -> String (3007.0) -
self.message のエイリアスです。
...self.message のエイリアスです。
//emlist[例][ruby]{
begin
Process.kill('HUP', Process.pid)
sleep
rescue SignalException => e
puts e.signm # => SIGHUP
end
//}... -
ThreadGroup
# enclose -> self (3007.0) -
自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。 enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。
...自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。
enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。
ただし、Thread.new によるスレッドの追加は禁止されません。enclose されたスレッ......します。
追加の例:
thg = ThreadGroup.new.enclose
thg.add Thread.new {}
=> -:2:in `add': can't move to the enclosed thread group (ThreadError)
削除の例:
thg1 = ThreadGroup.new
thg2 = ThreadGroup.new
th = Thread.new {sleep 1}
thg1.add th
thg1.enclose
thg2.add th......=> -:8:in `add': can't move from the enclosed thread group (ThreadError)... -
File
# flock(operation) -> 0 | false (131.0) -
ファイルをロックします。
...す。
@param operation ロックに対する操作の種類を示す定数を指定します。
どのような定数が利用可能かは以下を参照して下さい。
@raise IOError 自身が close されている場合に発生します。
@raise Errno::EXXX operation に......不正な整数を与えた場合などに発生します。
引数 operation に有効な定数は以下の通りです。定数は File::Constants で定義されていますが、
File クラスの親クラスの IO が File::Constants をインクルードしているので、
これらの定......けません。
File.open("counter", File::RDWR|File::CREAT, 0644) {|f|
f.flock(File::LOCK_EX)
value = f.read.to_i + 1
f.rewind
f.write("#{value}\n")
f.flush
f.truncate(f.pos)
}
# 読み込みロック(read lock)を使用してカウンタを読み込み。
File.open("counter", "r") {|f... -
Thread
# raise(error _ type , message , traceback) -> () (119.0) -
自身が表すスレッドで強制的に例外を発生させます。
...す。
@param error_type Kernel.#raise を参照してください。
@param message Kernel.#raise を参照してください。
@param traceback Kernel.#raise を参照してください。
Thread.new {
sleep 1
Thread.main.raise "foobar"
}
begin
sleep
rescue
p $!, $@... -
ThreadsWait
# join _ nowait(*threads) -> () (61.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。 しかし、実際には終了をまちません。
...了をまちません。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new
p thall.threads #=> []
th......all.join_nowait(*threads)
p thall.threads #=> [#<Thread:0x21638 sleep>, #<Thread:0x215ac sleep>, #<Thread:0x21520 sleep>, #<Thread:0x21494 sleep>, #<Thread:0x21408 sleep>]
# 実際には終了を待っていない。sleep している。... -
ThreadsWait
# threads -> Array (37.0) -
同期されるスレッドの一覧を配列で返します。
...ドの一覧を配列で返します。
使用例
require 'thwait'
threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
p thall.threads
#=> [#<Thread:0x21750 sleep>, #<Thread:0x216c4 sleep>, #<Thread:0x21638 sleep>]... -
Thread
# value -> object (31.0) -
スレッド self が終了するまで待ち(Thread#join と同じ)、 そのスレッドのブロックが返した値を返します。スレッド実行中に例外が 発生した場合には、その例外を再発生させます。
...果を出力する例です。
threads = []
threads.push(Thread.new { n = rand(5); sleep n; n })
threads.push(Thread.new { n = rand(5); sleep n; n })
threads.push(Thread.new { n = rand(5); sleep n; n })
threads.each {|t| p t.value}
最後の行で、待ち合わせを行ってい......ることがわかりにくいと思うなら以下
のように書くこともできます。
threads.each {|t| p t.join.value}... -
ThreadsWait
# finished? -> bool (31.0) -
すでに終了したスレッドが存在すれば true を返します。
...に終了したスレッドが存在すれば true を返します。
使用例
require 'thwait'
threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
p thall.finished? #=> false
sleep 3
p thall.finished? #=> true... -
File
:: Stat # <=>(o) -> Integer | nil (25.0) -
ファイルの最終更新時刻を比較します。self が other よりも 新しければ正の数を、等しければ 0 を古ければ負の数を返します。 比較できない場合は nil を返します。
...param o File::Stat のインスタンスを指定します。
//emlist[][ruby]{
require 'tempfile' # for Tempfile
fp1 = Tempfile.open("first")
fp1.print "古い方\n"
sleep(1)
fp2 = Tempfile.open("second")
fp2.print "新しい方\n"
p File::Stat.new(fp1.path) <=> File::Stat.new(fp2.path) #=> -1
p......File::Stat.new(fp2.path) <=> File::Stat.new(fp1.path) #=> 1
p File::Stat.new(fp1.path) <=> fp2.path #=> nil
//}...