mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/thwait.rb: revise rdoc. a patch from Roger Pack in
[ruby-core:27362]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dc22009c26
commit
c6871cef32
2 changed files with 14 additions and 35 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Apr 28 23:53:15 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
|
* lib/thwait.rb: revise rdoc. a patch from Roger Pack in
|
||||||
|
[ruby-core:27362].
|
||||||
|
|
||||||
Wed Apr 28 23:21:42 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Wed Apr 28 23:21:42 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ext/json: Update to JSON 1.4.2.
|
* ext/json: Update to JSON 1.4.2.
|
||||||
|
|
|
@ -3,37 +3,6 @@
|
||||||
# $Release Version: 0.9 $
|
# $Release Version: 0.9 $
|
||||||
# $Revision: 1.3 $
|
# $Revision: 1.3 $
|
||||||
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd.)
|
# by Keiju ISHITSUKA(Nihon 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 "thread.rb"
|
||||||
require "e2mmap.rb"
|
require "e2mmap.rb"
|
||||||
|
@ -50,6 +19,11 @@ require "e2mmap.rb"
|
||||||
# STDERR.puts "Thread #{t} has terminated."
|
# STDERR.puts "Thread #{t} has terminated."
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
#
|
||||||
|
# th = ThreadsWait.new(thread1,...)
|
||||||
|
# th.next_wait # next one to be done
|
||||||
|
#
|
||||||
|
#
|
||||||
class ThreadsWait
|
class ThreadsWait
|
||||||
RCS_ID='-$Id: thwait.rb,v 1.3 1998/06/26 03:19:34 keiju Exp keiju $-'
|
RCS_ID='-$Id: thwait.rb,v 1.3 1998/06/26 03:19:34 keiju Exp keiju $-'
|
||||||
|
|
||||||
|
@ -59,7 +33,7 @@ class ThreadsWait
|
||||||
|
|
||||||
#
|
#
|
||||||
# Waits until all specified threads have terminated. If a block is provided,
|
# 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
|
def ThreadsWait.all_waits(*threads) # :yield: thread
|
||||||
tw = ThreadsWait.new(*threads)
|
tw = ThreadsWait.new(*threads)
|
||||||
|
@ -82,18 +56,18 @@ class ThreadsWait
|
||||||
join_nowait(*threads) unless threads.empty?
|
join_nowait(*threads) unless threads.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the array of threads in the wait queue.
|
# Returns the array of threads that have not terminated yet.
|
||||||
attr :threads
|
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?
|
def empty?
|
||||||
@threads.empty?
|
@threads.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns +true+ if any thread has terminated.
|
# Returns +true+ if any thread has terminated and is ready to be collected.
|
||||||
#
|
#
|
||||||
def finished?
|
def finished?
|
||||||
!@wait_queue.empty?
|
!@wait_queue.empty?
|
||||||
|
|
Loading…
Reference in a new issue