rubysl-thwait 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +14 -6
- data/.travis.yml +5 -6
- data/lib/rubysl/thwait/thwait.rb +40 -73
- data/lib/rubysl/thwait/version.rb +1 -1
- data/rubysl-thwait.gemspec +0 -5
- metadata +11 -38
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGU5YmNiNTg3NWZmZjQ0NjE5M2M1M2JkYmQwNjZmMjlkMWIxYmRjOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTI4NTE5ODAwMWQ5NTIyYjVhN2U1Mjk4YTQ3ZDljZmJiN2M5Njg3OQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmI2ZDdlMmY1ZTlmYWMyYmQ3Y2ViNGM3YmFjMjRmZGZlMmRiMjRjMGU3Y2My
|
10
|
+
Yjg4YTgzNDNhNzA4ZmE5NzZjNWM4YmE3MzE3MTBkMjQ1MzQ4ZGMwNTkzNGEw
|
11
|
+
ZGQ3NzJiYTQwMGJkMWYzNGZkOGU4ZDljN2I0MjYyNzMzYzgwOTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzZmN2Q1MTBjMTYxMzBlNjdhMGQwNjgzYTg3ODliODZlMTY2ZWQ0MGE0Mjg1
|
14
|
+
Y2JkNWFhZmUwOTNmMGZkOWZmYTU2NjM5ZjhiODM1NDY2MGFmM2I3N2MwMjI1
|
15
|
+
MTE2M2FiNjY3MjNiNjEwNjkwNjZlYzBhOWY4NTE2Y2RiMzNlNmM=
|
data/.travis.yml
CHANGED
data/lib/rubysl/thwait/thwait.rb
CHANGED
@@ -1,42 +1,11 @@
|
|
1
1
|
#
|
2
2
|
# thwait.rb - thread synchronization class
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# by Keiju ISHITSUKA(Nihpon Rational Software Co.,Ltd.)
|
7
|
-
# modernized by Evan Phoenix - 2011
|
8
|
-
# --
|
9
|
-
# feature:
|
10
|
-
# provides synchronization for multiple threads.
|
11
|
-
#
|
12
|
-
# class methods:
|
13
|
-
# * ThreadsWait.all_waits(thread1,...)
|
14
|
-
# waits until all of specified threads are terminated.
|
15
|
-
# if a block is supplied for the method, evaluates it for
|
16
|
-
# each thread termination.
|
17
|
-
# * th = ThreadsWait.new(thread1,...)
|
18
|
-
# creates synchronization object, specifying thread(s) to wait.
|
19
|
-
#
|
20
|
-
# methods:
|
21
|
-
# * th.threads
|
22
|
-
# list threads to be synchronized
|
23
|
-
# * th.empty?
|
24
|
-
# is there any thread to be synchronized.
|
25
|
-
# * th.finished?
|
26
|
-
# is there already terminated thread.
|
27
|
-
# * th.join(thread1,...)
|
28
|
-
# wait for specified thread(s).
|
29
|
-
# * th.join_nowait(threa1,...)
|
30
|
-
# specifies thread(s) to wait. non-blocking.
|
31
|
-
# * th.next_wait
|
32
|
-
# waits until any of specified threads is terminated.
|
33
|
-
# * th.all_waits
|
34
|
-
# waits until all of specified threads are terminated.
|
35
|
-
# if a block is supplied for the method, evaluates it for
|
36
|
-
# each thread termination.
|
37
|
-
#
|
3
|
+
# $Release Version: 0.9 $
|
4
|
+
# $Revision: 1.3 $
|
5
|
+
# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd.)
|
38
6
|
|
39
|
-
require "thread"
|
7
|
+
require "thread.rb"
|
8
|
+
require "e2mmap.rb"
|
40
9
|
|
41
10
|
#
|
42
11
|
# This class watches for termination of multiple threads. Basic functionality
|
@@ -46,22 +15,25 @@ require "thread"
|
|
46
15
|
#
|
47
16
|
# Example:
|
48
17
|
#
|
49
|
-
# ThreadsWait.
|
18
|
+
# ThreadsWait.all_wait(thr1, thr2, ...) do |t|
|
50
19
|
# STDERR.puts "Thread #{t} has terminated."
|
51
20
|
# end
|
52
21
|
#
|
22
|
+
#
|
23
|
+
# th = ThreadsWait.new(thread1,...)
|
24
|
+
# th.next_wait # next one to be done
|
25
|
+
#
|
26
|
+
#
|
53
27
|
class ThreadsWait
|
54
|
-
RCS_ID='-$Id: thwait.rb
|
55
|
-
|
56
|
-
class ErrNoWaitingThread < StandardError
|
57
|
-
end
|
28
|
+
RCS_ID='-$Id: thwait.rb,v 1.3 1998/06/26 03:19:34 keiju Exp keiju $-'
|
58
29
|
|
59
|
-
|
60
|
-
|
30
|
+
extend Exception2MessageMapper
|
31
|
+
def_exception("ErrNoWaitingThread", "No threads for waiting.")
|
32
|
+
def_exception("ErrNoFinishedThread", "No finished threads.")
|
61
33
|
|
62
34
|
#
|
63
35
|
# Waits until all specified threads have terminated. If a block is provided,
|
64
|
-
# it is executed for each thread
|
36
|
+
# it is executed for each thread as they terminate.
|
65
37
|
#
|
66
38
|
def ThreadsWait.all_waits(*threads) # :yield: thread
|
67
39
|
tw = ThreadsWait.new(*threads)
|
@@ -73,7 +45,7 @@ class ThreadsWait
|
|
73
45
|
tw.all_waits
|
74
46
|
end
|
75
47
|
end
|
76
|
-
|
48
|
+
|
77
49
|
#
|
78
50
|
# Creates a ThreadsWait object, specifying the threads to wait on.
|
79
51
|
# Non-blocking.
|
@@ -83,32 +55,33 @@ class ThreadsWait
|
|
83
55
|
@wait_queue = Queue.new
|
84
56
|
join_nowait(*threads) unless threads.empty?
|
85
57
|
end
|
86
|
-
|
87
|
-
# Returns the array of threads
|
88
|
-
|
89
|
-
|
58
|
+
|
59
|
+
# Returns the array of threads that have not terminated yet.
|
60
|
+
attr :threads
|
61
|
+
|
90
62
|
#
|
91
|
-
# Returns +true+ if there are no threads
|
63
|
+
# Returns +true+ if there are no threads in the pool still running.
|
92
64
|
#
|
93
65
|
def empty?
|
94
66
|
@threads.empty?
|
95
67
|
end
|
96
|
-
|
68
|
+
|
97
69
|
#
|
98
|
-
# Returns +true+ if any thread has terminated.
|
70
|
+
# Returns +true+ if any thread has terminated and is ready to be collected.
|
99
71
|
#
|
100
72
|
def finished?
|
101
73
|
!@wait_queue.empty?
|
102
74
|
end
|
103
|
-
|
75
|
+
|
104
76
|
#
|
105
|
-
# Waits for specified threads to terminate
|
77
|
+
# Waits for specified threads to terminate, and returns when one of
|
78
|
+
# the threads terminated.
|
106
79
|
#
|
107
80
|
def join(*threads)
|
108
81
|
join_nowait(*threads)
|
109
82
|
next_wait
|
110
83
|
end
|
111
|
-
|
84
|
+
|
112
85
|
#
|
113
86
|
# Specifies the threads that this object will wait for, but does not actually
|
114
87
|
# wait.
|
@@ -116,8 +89,7 @@ class ThreadsWait
|
|
116
89
|
def join_nowait(*threads)
|
117
90
|
threads.flatten!
|
118
91
|
@threads.concat threads
|
119
|
-
|
120
|
-
threads.each do |th|
|
92
|
+
for th in threads
|
121
93
|
Thread.start(th) do |t|
|
122
94
|
begin
|
123
95
|
t.join
|
@@ -127,27 +99,24 @@ class ThreadsWait
|
|
127
99
|
end
|
128
100
|
end
|
129
101
|
end
|
130
|
-
|
102
|
+
|
131
103
|
#
|
132
104
|
# Waits until any of the specified threads has terminated, and returns the one
|
133
105
|
# that does.
|
134
106
|
#
|
135
|
-
# If there
|
136
|
-
#
|
137
|
-
# raises +ErrNoFinishedThread+.
|
107
|
+
# If there is no thread to wait, raises +ErrNoWaitingThread+. If +nonblock+
|
108
|
+
# is true, and there is no terminated thread, raises +ErrNoFinishedThread+.
|
138
109
|
#
|
139
|
-
def next_wait(nonblock=nil)
|
140
|
-
|
141
|
-
|
110
|
+
def next_wait(nonblock = nil)
|
111
|
+
ThreadsWait.fail ErrNoWaitingThread if @threads.empty?
|
142
112
|
begin
|
143
|
-
th = @wait_queue.pop(nonblock)
|
144
|
-
|
145
|
-
return th
|
113
|
+
@threads.delete(th = @wait_queue.pop(nonblock))
|
114
|
+
th
|
146
115
|
rescue ThreadError
|
147
|
-
|
116
|
+
ThreadsWait.fail ErrNoFinishedThread
|
148
117
|
end
|
149
118
|
end
|
150
|
-
|
119
|
+
|
151
120
|
#
|
152
121
|
# Waits until all of the specified threads are terminated. If a block is
|
153
122
|
# supplied for the method, it is executed for each thread termination.
|
@@ -162,7 +131,8 @@ class ThreadsWait
|
|
162
131
|
end
|
163
132
|
end
|
164
133
|
|
165
|
-
|
134
|
+
##
|
135
|
+
# An alias for ThreadsWait from thwait.rb
|
166
136
|
|
167
137
|
ThWait = ThreadsWait
|
168
138
|
|
@@ -170,6 +140,3 @@ ThWait = ThreadsWait
|
|
170
140
|
# - Source of documentation is evenly split between Nutshell, existing
|
171
141
|
# comments, and my own rephrasing.
|
172
142
|
# - I'm not particularly confident that the comments are all exactly correct.
|
173
|
-
# - The history, etc., up the top appears in the RDoc output. Perhaps it would
|
174
|
-
# be better to direct that not to appear, and put something else there
|
175
|
-
# instead.
|
data/rubysl-thwait.gemspec
CHANGED
@@ -16,12 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.required_ruby_version = "~> 1.8.7"
|
20
|
-
|
21
|
-
spec.add_runtime_dependency "rubysl-thread", "~> 1.0"
|
22
|
-
|
23
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
20
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
21
|
spec.add_development_dependency "mspec", "~> 1.5"
|
26
|
-
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
27
22
|
end
|
metadata
CHANGED
@@ -1,30 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-thwait
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: rubysl-thread
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
14
|
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
15
|
name: bundler
|
29
16
|
requirement: !ruby/object:Gem::Requirement
|
30
17
|
requirements:
|
@@ -32,13 +19,13 @@ dependencies:
|
|
32
19
|
- !ruby/object:Gem::Version
|
33
20
|
version: '1.3'
|
34
21
|
type: :development
|
35
|
-
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - ~>
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '1.3'
|
41
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
prerelease: false
|
42
29
|
name: rake
|
43
30
|
requirement: !ruby/object:Gem::Requirement
|
44
31
|
requirements:
|
@@ -46,13 +33,13 @@ dependencies:
|
|
46
33
|
- !ruby/object:Gem::Version
|
47
34
|
version: '10.0'
|
48
35
|
type: :development
|
49
|
-
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - ~>
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '10.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
prerelease: false
|
56
43
|
name: mspec
|
57
44
|
requirement: !ruby/object:Gem::Requirement
|
58
45
|
requirements:
|
@@ -60,26 +47,11 @@ dependencies:
|
|
60
47
|
- !ruby/object:Gem::Version
|
61
48
|
version: '1.5'
|
62
49
|
type: :development
|
63
|
-
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - ~>
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '1.5'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubysl-prettyprint
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ~>
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.0'
|
83
55
|
description: Ruby standard library threads_wait.
|
84
56
|
email:
|
85
57
|
- brixen@gmail.com
|
@@ -108,19 +80,20 @@ require_paths:
|
|
108
80
|
- lib
|
109
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
82
|
requirements:
|
111
|
-
- -
|
83
|
+
- - ! '>='
|
112
84
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
85
|
+
version: !binary |-
|
86
|
+
MA==
|
114
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
88
|
requirements:
|
116
|
-
- - '>='
|
89
|
+
- - ! '>='
|
117
90
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
91
|
+
version: !binary |-
|
92
|
+
MA==
|
119
93
|
requirements: []
|
120
94
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.0.
|
95
|
+
rubygems_version: 2.0.6
|
122
96
|
signing_key:
|
123
97
|
specification_version: 4
|
124
98
|
summary: Ruby standard library threads_wait.
|
125
99
|
test_files: []
|
126
|
-
has_rdoc:
|