rubysl-thwait 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rubysl/thwait.rb +2 -0
- data/lib/rubysl/thwait/thwait.rb +175 -0
- data/lib/rubysl/thwait/version.rb +5 -0
- data/lib/thwait.rb +1 -0
- data/rubysl-thwait.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40906ea355b3bfdfa40b94426b8b51aba99e5936
|
4
|
+
data.tar.gz: 09a29ae3102328fa032ada0cdb9764ee4cf66acc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bd3b46c121211699a4a90738f49d22525eaa11be9cbfcee811ce4c22c339a451a70e447745000ffa0ab76f75ea606851ec56724afb01b90f5b49917ac159011
|
7
|
+
data.tar.gz: a7e449b7ff975b48e2f8471455090e223ce5bcc3ae4dfd7c475246a24781391061bb9c173c8d51a3bab8fecd7981bfd49b631a23a4dfd679741481ca7e48b35e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubysl::ThreadsWait
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubysl-threads_wait'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubysl-threads_wait
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,175 @@
|
|
1
|
+
#
|
2
|
+
# thwait.rb - thread synchronization class
|
3
|
+
# $Release Version: 0.9 $
|
4
|
+
# $Revision: 1.3 $
|
5
|
+
# $Date: 1998/06/26 03:19:34 $
|
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
|
+
#
|
38
|
+
|
39
|
+
require "thread"
|
40
|
+
|
41
|
+
#
|
42
|
+
# This class watches for termination of multiple threads. Basic functionality
|
43
|
+
# (wait until specified threads have terminated) can be accessed through the
|
44
|
+
# class method ThreadsWait::all_waits. Finer control can be gained using
|
45
|
+
# instance methods.
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
#
|
49
|
+
# ThreadsWait.all_waits(thr1, thr2, ...) do |t|
|
50
|
+
# STDERR.puts "Thread #{t} has terminated."
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
class ThreadsWait
|
54
|
+
RCS_ID='-$Id: thwait.rb:git 1.4 2011/01/24 00:00:00 evan $-'
|
55
|
+
|
56
|
+
class ErrNoWaitingThread < StandardError
|
57
|
+
end
|
58
|
+
|
59
|
+
class ErrNoFinishedThread < StandardError
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Waits until all specified threads have terminated. If a block is provided,
|
64
|
+
# it is executed for each thread termination.
|
65
|
+
#
|
66
|
+
def ThreadsWait.all_waits(*threads) # :yield: thread
|
67
|
+
tw = ThreadsWait.new(*threads)
|
68
|
+
if block_given?
|
69
|
+
tw.all_waits do |th|
|
70
|
+
yield th
|
71
|
+
end
|
72
|
+
else
|
73
|
+
tw.all_waits
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Creates a ThreadsWait object, specifying the threads to wait on.
|
79
|
+
# Non-blocking.
|
80
|
+
#
|
81
|
+
def initialize(*threads)
|
82
|
+
@threads = []
|
83
|
+
@wait_queue = Queue.new
|
84
|
+
join_nowait(*threads) unless threads.empty?
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns the array of threads in the wait queue.
|
88
|
+
attr_reader :threads
|
89
|
+
|
90
|
+
#
|
91
|
+
# Returns +true+ if there are no threads to be synchronized.
|
92
|
+
#
|
93
|
+
def empty?
|
94
|
+
@threads.empty?
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Returns +true+ if any thread has terminated.
|
99
|
+
#
|
100
|
+
def finished?
|
101
|
+
!@wait_queue.empty?
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Waits for specified threads to terminate.
|
106
|
+
#
|
107
|
+
def join(*threads)
|
108
|
+
join_nowait(*threads)
|
109
|
+
next_wait
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Specifies the threads that this object will wait for, but does not actually
|
114
|
+
# wait.
|
115
|
+
#
|
116
|
+
def join_nowait(*threads)
|
117
|
+
threads.flatten!
|
118
|
+
@threads.concat threads
|
119
|
+
|
120
|
+
threads.each do |th|
|
121
|
+
Thread.start(th) do |t|
|
122
|
+
begin
|
123
|
+
t.join
|
124
|
+
ensure
|
125
|
+
@wait_queue.push t
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# Waits until any of the specified threads has terminated, and returns the one
|
133
|
+
# that does.
|
134
|
+
#
|
135
|
+
# If there are no pending threads to wait for, raises +ErrNoWaitingThread+.
|
136
|
+
# If +nonblock+ is true and there is no terminated thread,
|
137
|
+
# raises +ErrNoFinishedThread+.
|
138
|
+
#
|
139
|
+
def next_wait(nonblock=nil)
|
140
|
+
raise ErrNoWaitingThread, "No threads for waiting" if @threads.empty?
|
141
|
+
|
142
|
+
begin
|
143
|
+
th = @wait_queue.pop(nonblock)
|
144
|
+
@threads.delete th
|
145
|
+
return th
|
146
|
+
rescue ThreadError
|
147
|
+
raise ErrNoFinishedThread, "No finished threads"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Waits until all of the specified threads are terminated. If a block is
|
153
|
+
# supplied for the method, it is executed for each thread termination.
|
154
|
+
#
|
155
|
+
# Raises exceptions in the same manner as +next_wait+.
|
156
|
+
#
|
157
|
+
def all_waits
|
158
|
+
until @threads.empty?
|
159
|
+
th = next_wait
|
160
|
+
yield th if block_given?
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# deprecated alias
|
166
|
+
|
167
|
+
ThWait = ThreadsWait
|
168
|
+
|
169
|
+
# Documentation comments:
|
170
|
+
# - Source of documentation is evenly split between Nutshell, existing
|
171
|
+
# comments, and my own rephrasing.
|
172
|
+
# - 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/lib/thwait.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/thwait"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/thwait/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-thwait"
|
6
|
+
spec.version = RubySL::ThreadsWait::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library threads_wait.}
|
10
|
+
spec.summary = %q{Ruby standard library threads_wait.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-threads_wait"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.required_ruby_version = "~> 1.8.7"
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rubysl-thread", "~> 1.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
26
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysl-thwait
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
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
|
+
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
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
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
|
+
description: Ruby standard library threads_wait.
|
84
|
+
email:
|
85
|
+
- brixen@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .travis.yml
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/rubysl/thwait.rb
|
97
|
+
- lib/rubysl/thwait/thwait.rb
|
98
|
+
- lib/rubysl/thwait/version.rb
|
99
|
+
- lib/thwait.rb
|
100
|
+
- rubysl-thwait.gemspec
|
101
|
+
homepage: https://github.com/rubysl/rubysl-threads_wait
|
102
|
+
licenses:
|
103
|
+
- BSD
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ~>
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.8.7
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.7
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruby standard library threads_wait.
|
125
|
+
test_files: []
|
126
|
+
has_rdoc:
|