rbs 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.gitignore +0 -1
- data/CHANGELOG.md +7 -2
- data/Gemfile +3 -0
- data/README.md +8 -2
- data/Steepfile +1 -0
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/docs/CONTRIBUTING.md +1 -0
- data/goodcheck.yml +22 -5
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/definition_builder.rb +4 -5
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3146 -0
- data/lib/rbs/parser.y +7 -2
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/type_check.rb +2 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/variance_calculator.rb +1 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +1 -1
- data/sig/constant.rbs +2 -2
- data/sig/constant_table.rbs +10 -10
- data/sig/declarations.rbs +1 -1
- data/sig/definition.rbs +1 -1
- data/sig/namespace.rbs +3 -3
- data/sig/parser.rbs +25 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/writer.rbs +15 -15
- data/stdlib/benchmark/benchmark.rbs +2 -2
- data/stdlib/builtin/basic_object.rbs +54 -54
- data/stdlib/builtin/binding.rbs +42 -42
- data/stdlib/builtin/class.rbs +33 -33
- data/stdlib/builtin/complex.rbs +90 -90
- data/stdlib/builtin/encoding.rbs +33 -33
- data/stdlib/builtin/enumerable.rbs +32 -32
- data/stdlib/builtin/enumerator.rbs +35 -35
- data/stdlib/builtin/errors.rbs +1 -1
- data/stdlib/builtin/exception.rbs +50 -50
- data/stdlib/builtin/false_class.rbs +6 -6
- data/stdlib/builtin/fiber.rbs +14 -14
- data/stdlib/builtin/fiber_error.rbs +1 -1
- data/stdlib/builtin/float.rbs +161 -161
- data/stdlib/builtin/gc.rbs +1 -1
- data/stdlib/builtin/io.rbs +83 -83
- data/stdlib/builtin/kernel.rbs +69 -69
- data/stdlib/builtin/match_data.rbs +1 -1
- data/stdlib/builtin/method.rbs +19 -19
- data/stdlib/builtin/nil_class.rbs +20 -20
- data/stdlib/builtin/numeric.rbs +101 -101
- data/stdlib/builtin/object.rbs +172 -172
- data/stdlib/builtin/proc.rbs +91 -91
- data/stdlib/builtin/range.rbs +2 -4
- data/stdlib/builtin/rational.rbs +83 -83
- data/stdlib/builtin/signal.rbs +7 -7
- data/stdlib/builtin/string.rbs +4 -4
- data/stdlib/builtin/string_io.rbs +1 -1
- data/stdlib/builtin/thread.rbs +185 -185
- data/stdlib/builtin/thread_group.rbs +2 -2
- data/stdlib/builtin/true_class.rbs +9 -9
- data/stdlib/builtin/warning.rbs +1 -1
- data/stdlib/date/date.rbs +2 -2
- data/stdlib/find/find.rbs +10 -10
- data/stdlib/pathname/pathname.rbs +1 -1
- data/stdlib/tmpdir/tmpdir.rbs +12 -12
- metadata +3 -2
data/stdlib/builtin/signal.rbs
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# trapped at the code level and acted upon. For example, your process may
|
4
4
|
# trap the USR1 signal and use it to toggle debugging, and may use TERM to
|
5
5
|
# initiate a controlled shutdown.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# ```ruby
|
8
8
|
# pid = fork do
|
9
9
|
# Signal.trap("USR1") do
|
@@ -16,9 +16,9 @@
|
|
16
16
|
# end
|
17
17
|
# # . . . do some work . . .
|
18
18
|
# end
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# Process.detach(pid)
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# # Controlling program:
|
23
23
|
# Process.kill("USR1", pid)
|
24
24
|
# # ...
|
@@ -26,15 +26,15 @@
|
|
26
26
|
# # ...
|
27
27
|
# Process.kill("TERM", pid)
|
28
28
|
# ```
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# produces:
|
31
|
-
#
|
31
|
+
#
|
32
32
|
# ```
|
33
33
|
# Debug now: true
|
34
34
|
# Debug now: false
|
35
35
|
# Terminating...
|
36
36
|
# ```
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# The list of available signal names and their interpretation is system
|
39
39
|
# dependent. [Signal](Signal) delivery semantics may
|
40
40
|
# also vary between systems; in particular signal delivery may not always
|
@@ -42,7 +42,7 @@
|
|
42
42
|
module Signal
|
43
43
|
# Returns a list of signal names mapped to the corresponding underlying
|
44
44
|
# signal numbers.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# ```ruby
|
47
47
|
# Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
|
48
48
|
# ```
|
data/stdlib/builtin/string.rbs
CHANGED
@@ -456,7 +456,7 @@ class String
|
|
456
456
|
#
|
457
457
|
# * On some OSes such as Mac OS, `crypt(3)` is not thread safe.
|
458
458
|
#
|
459
|
-
# * So-called "traditional" usage of `crypt(3)` is very very very weak.
|
459
|
+
# * So-called "traditional" usage of `crypt(3)` is very very very weak.
|
460
460
|
# According to its manpage, Linux's traditional `crypt(3)` output has only
|
461
461
|
# 2**56 variations; too easy to brute force today. And this is the default
|
462
462
|
# behaviour.
|
@@ -735,7 +735,7 @@ class String
|
|
735
735
|
# : Sets the replacement string to the given value. The default replacement
|
736
736
|
# string is "uFFFD" for Unicode encoding forms, and "?" otherwise.
|
737
737
|
# :fallback
|
738
|
-
# : Sets the replacement string by the given object for undefined character.
|
738
|
+
# : Sets the replacement string by the given object for undefined character.
|
739
739
|
# The object should be a Hash, a Proc, a Method, or an object which has []
|
740
740
|
# method. Its key is an undefined character encoded in the source encoding
|
741
741
|
# of current transcoder. Its value can be any encoding until it can be
|
@@ -1532,7 +1532,7 @@ class String
|
|
1532
1532
|
#
|
1533
1533
|
def to_i: (?int base) -> Integer
|
1534
1534
|
|
1535
|
-
# Returns the result of interpreting leading characters in `str` as a rational.
|
1535
|
+
# Returns the result of interpreting leading characters in `str` as a rational.
|
1536
1536
|
# Leading whitespace and extraneous characters past the end of a valid number
|
1537
1537
|
# are ignored. Digit sequences can be separated by an underscore. If there is
|
1538
1538
|
# not a valid number at the start of `str`, zero is returned. This method never
|
@@ -1806,7 +1806,7 @@ class String
|
|
1806
1806
|
# In that case data would be lost but often it's the case that the array only
|
1807
1807
|
# holds one value, especially when unpacking binary data. For instance:
|
1808
1808
|
#
|
1809
|
-
# "xffx00x00x00".unpack("l") #=> [255] "xffx00x00x00".unpack1("l")
|
1809
|
+
# "xffx00x00x00".unpack("l") #=> [255] "xffx00x00x00".unpack1("l")
|
1810
1810
|
# #=> 255
|
1811
1811
|
#
|
1812
1812
|
# Thus unpack1 is convenient, makes clear the intention and signals the expected
|
@@ -114,7 +114,7 @@ class StringIO
|
|
114
114
|
#
|
115
115
|
def gets: (?String sep, ?Integer limit, ?chomp: bool) -> String?
|
116
116
|
|
117
|
-
# Returns the Encoding of the internal string if conversion is specified.
|
117
|
+
# Returns the Encoding of the internal string if conversion is specified.
|
118
118
|
# Otherwise returns `nil`.
|
119
119
|
#
|
120
120
|
def internal_encoding: () -> Encoding
|
data/stdlib/builtin/thread.rbs
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
# Threads are the Ruby implementation for a concurrent programming model.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Programs that require multiple threads of execution are a perfect
|
4
4
|
# candidate for Ruby's [Thread](Thread) class.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# For example, we can create a new thread separate from the main thread's
|
7
7
|
# execution using [::new](Thread#method-c-new).
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# ```ruby
|
10
10
|
# thr = Thread.new { puts "Whats the big deal" }
|
11
11
|
# ```
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Then we are able to pause the execution of the main thread and allow our
|
14
14
|
# new thread to finish, using
|
15
15
|
# [join](Thread#method-i-join):
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# ```ruby
|
18
18
|
# thr.join #=> "Whats the big deal"
|
19
19
|
# ```
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# If we don't call `thr.join` before the main thread terminates, then all
|
22
22
|
# other threads including `thr` will be killed.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# Alternatively, you can use an array for handling multiple threads at
|
25
25
|
# once, like in the following example:
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# ```ruby
|
28
28
|
# threads = []
|
29
29
|
# threads << Thread.new { puts "Whats the big deal" }
|
30
30
|
# threads << Thread.new { 3.times { puts "Threads are fun!" } }
|
31
31
|
# ```
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# After creating a few threads we wait for them all to finish
|
34
34
|
# consecutively.
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# ```ruby
|
37
37
|
# threads.each { |thr| thr.join }
|
38
38
|
# ```
|
39
|
-
#
|
40
|
-
#
|
39
|
+
#
|
40
|
+
#
|
41
41
|
# In order to create new threads, Ruby provides
|
42
42
|
# [::new](Thread#method-c-new),
|
43
43
|
# [::start](Thread#method-c-start), and
|
@@ -45,59 +45,59 @@
|
|
45
45
|
# provided with each of these methods, otherwise a
|
46
46
|
# [ThreadError](https://ruby-doc.org/core-2.6.3/ThreadError.html) will be
|
47
47
|
# raised.
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# When subclassing the [Thread](Thread) class, the
|
50
50
|
# `initialize` method of your subclass will be ignored by
|
51
51
|
# [::start](Thread#method-c-start) and
|
52
52
|
# [::fork](Thread#method-c-fork). Otherwise, be sure
|
53
53
|
# to call super in your `initialize` method.
|
54
|
-
#
|
55
|
-
#
|
54
|
+
#
|
55
|
+
#
|
56
56
|
# For terminating threads, Ruby provides a variety of ways to do this.
|
57
|
-
#
|
57
|
+
#
|
58
58
|
# The class method [::kill](Thread#method-c-kill), is
|
59
59
|
# meant to exit a given thread:
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# thr = Thread.new { ... }
|
62
62
|
# Thread.kill(thr) # sends exit() to thr
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# Alternatively, you can use the instance method
|
65
65
|
# [exit](Thread#method-i-exit), or any of its aliases
|
66
66
|
# [kill](Thread#method-i-kill) or
|
67
67
|
# [terminate](Thread#method-i-terminate).
|
68
|
-
#
|
68
|
+
#
|
69
69
|
# ```ruby
|
70
70
|
# thr.exit
|
71
71
|
# ```
|
72
|
-
#
|
73
|
-
#
|
72
|
+
#
|
73
|
+
#
|
74
74
|
# Ruby provides a few instance methods for querying the state of a given
|
75
75
|
# thread. To get a string with the current thread's state use
|
76
76
|
# [status](Thread#method-i-status)
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# ```ruby
|
79
79
|
# thr = Thread.new { sleep }
|
80
80
|
# thr.status # => "sleep"
|
81
81
|
# thr.exit
|
82
82
|
# thr.status # => false
|
83
83
|
# ```
|
84
|
-
#
|
84
|
+
#
|
85
85
|
# You can also use [alive?](Thread#method-i-alive-3F)
|
86
86
|
# to tell if the thread is running or sleeping, and
|
87
87
|
# [stop?](Thread#method-i-stop-3F) if the thread is
|
88
88
|
# dead or sleeping.
|
89
|
-
#
|
90
|
-
#
|
89
|
+
#
|
90
|
+
#
|
91
91
|
# Since threads are created with blocks, the same rules apply to other
|
92
92
|
# Ruby blocks for variable scope. Any local variables created within this
|
93
93
|
# block are accessible to only this thread.
|
94
|
-
#
|
95
|
-
#
|
94
|
+
#
|
95
|
+
#
|
96
96
|
# Each fiber has its own bucket for
|
97
97
|
# [\#\[\]](Thread#method-i-5B-5D) storage. When you
|
98
98
|
# set a new fiber-local it is only accessible within this
|
99
99
|
# [Fiber](https://ruby-doc.org/core-2.6.3/Fiber.html). To illustrate:
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# ```ruby
|
102
102
|
# Thread.new {
|
103
103
|
# Thread.current[:foo] = "bar"
|
@@ -106,7 +106,7 @@
|
|
106
106
|
# }.resume
|
107
107
|
# }.join
|
108
108
|
# ```
|
109
|
-
#
|
109
|
+
#
|
110
110
|
# This example uses [\[\]](Thread#method-i-5B-5D) for
|
111
111
|
# getting and [\[\]=](Thread#method-i-5B-5D-3D) for
|
112
112
|
# setting fiber-locals, you can also use
|
@@ -114,10 +114,10 @@
|
|
114
114
|
# fiber-locals for a given thread and
|
115
115
|
# [key?](Thread#method-i-key-3F) to check if a
|
116
116
|
# fiber-local exists.
|
117
|
-
#
|
117
|
+
#
|
118
118
|
# When it comes to thread-locals, they are accessible within the entire
|
119
119
|
# scope of the thread. Given the following example:
|
120
|
-
#
|
120
|
+
#
|
121
121
|
# ```ruby
|
122
122
|
# Thread.new{
|
123
123
|
# Thread.current.thread_variable_set(:foo, 1)
|
@@ -129,29 +129,29 @@
|
|
129
129
|
# p Thread.current.thread_variable_get(:foo) # => 2
|
130
130
|
# }.join
|
131
131
|
# ```
|
132
|
-
#
|
132
|
+
#
|
133
133
|
# You can see that the thread-local `:foo` carried over into the fiber and
|
134
134
|
# was changed to `2` by the end of the thread.
|
135
|
-
#
|
135
|
+
#
|
136
136
|
# This example makes use of
|
137
137
|
# [thread\_variable\_set](Thread#method-i-thread_variable_set)
|
138
138
|
# to create new thread-locals, and
|
139
139
|
# [thread\_variable\_get](Thread#method-i-thread_variable_get)
|
140
140
|
# to reference them.
|
141
|
-
#
|
141
|
+
#
|
142
142
|
# There is also
|
143
143
|
# [thread\_variables](Thread#method-i-thread_variables)
|
144
144
|
# to list all thread-locals, and
|
145
145
|
# [thread\_variable?](Thread#method-i-thread_variable-3F)
|
146
146
|
# to check if a given thread-local exists.
|
147
|
-
#
|
148
|
-
#
|
147
|
+
#
|
148
|
+
#
|
149
149
|
# Any thread can raise an exception using the
|
150
150
|
# [raise](Thread#method-i-raise) instance method,
|
151
151
|
# which operates similarly to
|
152
152
|
# [Kernel\#raise](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-raise)
|
153
153
|
# .
|
154
|
-
#
|
154
|
+
#
|
155
155
|
# However, it's important to note that an exception that occurs in any
|
156
156
|
# thread except the main thread depends on
|
157
157
|
# [abort\_on\_exception](Thread#method-i-abort_on_exception)
|
@@ -162,22 +162,22 @@
|
|
162
162
|
# default by either
|
163
163
|
# [abort\_on\_exception=](Thread#method-i-abort_on_exception-3D)
|
164
164
|
# `true` or setting $DEBUG to `true` .
|
165
|
-
#
|
165
|
+
#
|
166
166
|
# With the addition of the class method
|
167
167
|
# [::handle\_interrupt](Thread#method-c-handle_interrupt)
|
168
168
|
# , you can now handle exceptions asynchronously with threads.
|
169
|
-
#
|
170
|
-
#
|
169
|
+
#
|
170
|
+
#
|
171
171
|
# Ruby provides a few ways to support scheduling threads in your program.
|
172
|
-
#
|
172
|
+
#
|
173
173
|
# The first way is by using the class method
|
174
174
|
# [::stop](Thread#method-c-stop), to put the current
|
175
175
|
# running thread to sleep and schedule the execution of another thread.
|
176
|
-
#
|
176
|
+
#
|
177
177
|
# Once a thread is asleep, you can use the instance method
|
178
178
|
# [wakeup](Thread#method-i-wakeup) to mark your thread
|
179
179
|
# as eligible for scheduling.
|
180
|
-
#
|
180
|
+
#
|
181
181
|
# You can also try [::pass](Thread#method-c-pass),
|
182
182
|
# which attempts to pass execution to another thread but is dependent on
|
183
183
|
# the OS whether a running thread will switch or not. The same goes for
|
@@ -195,9 +195,9 @@ class Thread < Object
|
|
195
195
|
|
196
196
|
# Attribute Assignment—Sets or creates the value of a fiber-local
|
197
197
|
# variable, using either a symbol or a string.
|
198
|
-
#
|
198
|
+
#
|
199
199
|
# See also [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D).
|
200
|
-
#
|
200
|
+
#
|
201
201
|
# For thread-local variables, please see
|
202
202
|
# [thread\_variable\_set](Thread.downloaded.ruby_doc#method-i-thread_variable_set)
|
203
203
|
# and
|
@@ -208,23 +208,23 @@ class Thread < Object
|
|
208
208
|
def alive?: () -> bool
|
209
209
|
|
210
210
|
# Terminates `thr` and schedules another thread to be run.
|
211
|
-
#
|
211
|
+
#
|
212
212
|
# If this thread is already marked to be killed,
|
213
213
|
# [exit](Thread.downloaded.ruby_doc#method-i-exit) returns the
|
214
214
|
# [Thread](Thread.downloaded.ruby_doc).
|
215
|
-
#
|
215
|
+
#
|
216
216
|
# If this is the main thread, or the last thread, exits the process.
|
217
217
|
def kill: () -> Thread?
|
218
218
|
|
219
219
|
# Returns the status of the thread-local “abort on exception” condition
|
220
220
|
# for this `thr` .
|
221
|
-
#
|
221
|
+
#
|
222
222
|
# The default is `false` .
|
223
|
-
#
|
223
|
+
#
|
224
224
|
# See also
|
225
225
|
# [abort\_on\_exception=](Thread.downloaded.ruby_doc#method-i-abort_on_exception-3D)
|
226
226
|
# .
|
227
|
-
#
|
227
|
+
#
|
228
228
|
# There is also a class level method to set this for all threads, see
|
229
229
|
# [::abort\_on\_exception](Thread.downloaded.ruby_doc#method-c-abort_on_exception)
|
230
230
|
# .
|
@@ -232,18 +232,18 @@ class Thread < Object
|
|
232
232
|
|
233
233
|
# When set to `true`, if this `thr` is aborted by an exception, the
|
234
234
|
# raised exception will be re-raised in the main thread.
|
235
|
-
#
|
235
|
+
#
|
236
236
|
# See also
|
237
237
|
# [abort\_on\_exception](Thread.downloaded.ruby_doc#method-i-abort_on_exception)
|
238
238
|
# .
|
239
|
-
#
|
239
|
+
#
|
240
240
|
# There is also a class level method to set this for all threads, see
|
241
241
|
# [::abort\_on\_exception=](Thread.downloaded.ruby_doc#method-c-abort_on_exception-3D)
|
242
242
|
# .
|
243
243
|
def abort_on_exception=: (bool abort_on_exception) -> untyped
|
244
244
|
|
245
245
|
# Adds *proc* as a handler for tracing.
|
246
|
-
#
|
246
|
+
#
|
247
247
|
# See
|
248
248
|
# [\#set\_trace\_func](Thread.downloaded.ruby_doc#method-i-set_trace_func)
|
249
249
|
# and
|
@@ -256,22 +256,22 @@ class Thread < Object
|
|
256
256
|
|
257
257
|
# Returns the execution stack for the target thread—an array containing
|
258
258
|
# backtrace location objects.
|
259
|
-
#
|
259
|
+
#
|
260
260
|
# See
|
261
261
|
# [Thread::Backtrace::Location](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
|
262
262
|
# for more information.
|
263
|
-
#
|
263
|
+
#
|
264
264
|
# This method behaves similarly to
|
265
265
|
# [Kernel\#caller\_locations](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-caller_locations)
|
266
266
|
# except it applies to a specific thread.
|
267
267
|
def backtrace_locations: (*untyped args) -> ::Array[untyped]?
|
268
268
|
|
269
269
|
# Terminates `thr` and schedules another thread to be run.
|
270
|
-
#
|
270
|
+
#
|
271
271
|
# If this thread is already marked to be killed,
|
272
272
|
# [exit](Thread.downloaded.ruby_doc#method-i-exit) returns the
|
273
273
|
# [Thread](Thread.downloaded.ruby_doc).
|
274
|
-
#
|
274
|
+
#
|
275
275
|
# If this is the main thread, or the last thread, exits the process.
|
276
276
|
def exit: () -> Thread?
|
277
277
|
|
@@ -290,36 +290,36 @@ class Thread < Object
|
|
290
290
|
def initialize: (*untyped args) -> Thread
|
291
291
|
|
292
292
|
# The calling thread will suspend execution and run this `thr` .
|
293
|
-
#
|
293
|
+
#
|
294
294
|
# Does not return until `thr` exits or until the given `limit` seconds
|
295
295
|
# have passed.
|
296
|
-
#
|
296
|
+
#
|
297
297
|
# If the time limit expires, `nil` will be returned, otherwise `thr` is
|
298
298
|
# returned.
|
299
|
-
#
|
299
|
+
#
|
300
300
|
# Any threads not joined will be killed when the main program exits.
|
301
|
-
#
|
301
|
+
#
|
302
302
|
# If `thr` had previously raised an exception and the
|
303
303
|
# [::abort\_on\_exception](Thread.downloaded.ruby_doc#method-c-abort_on_exception)
|
304
304
|
# or $DEBUG flags are not set, (so the exception has not yet been
|
305
305
|
# processed), it will be processed at this time.
|
306
|
-
#
|
306
|
+
#
|
307
307
|
# ```ruby
|
308
308
|
# a = Thread.new { print "a"; sleep(10); print "b"; print "c" }
|
309
309
|
# x = Thread.new { print "x"; Thread.pass; print "y"; print "z" }
|
310
310
|
# x.join # Let thread x finish, thread a will be killed on exit.
|
311
311
|
# #=> "axyz"
|
312
312
|
# ```
|
313
|
-
#
|
313
|
+
#
|
314
314
|
# The following example illustrates the `limit` parameter.
|
315
|
-
#
|
315
|
+
#
|
316
316
|
# ```ruby
|
317
317
|
# y = Thread.new { 4.times { sleep 0.1; puts 'tick... ' }}
|
318
318
|
# puts "Waiting" until y.join(0.15)
|
319
319
|
# ```
|
320
|
-
#
|
320
|
+
#
|
321
321
|
# This will produce:
|
322
|
-
#
|
322
|
+
#
|
323
323
|
# tick...
|
324
324
|
# Waiting
|
325
325
|
# tick...
|
@@ -330,7 +330,7 @@ class Thread < Object
|
|
330
330
|
|
331
331
|
# Returns `true` if the given string (or symbol) exists as a fiber-local
|
332
332
|
# variable.
|
333
|
-
#
|
333
|
+
#
|
334
334
|
# ```ruby
|
335
335
|
# me = Thread.current
|
336
336
|
# me[:oliver] = "a"
|
@@ -350,9 +350,9 @@ class Thread < Object
|
|
350
350
|
|
351
351
|
# Returns whether or not the asynchronous queue is empty for the target
|
352
352
|
# thread.
|
353
|
-
#
|
353
|
+
#
|
354
354
|
# If `error` is given, then check only for `error` type deferred events.
|
355
|
-
#
|
355
|
+
#
|
356
356
|
# See
|
357
357
|
# [::pending\_interrupt?](Thread.downloaded.ruby_doc#method-c-pending_interrupt-3F)
|
358
358
|
# for more information.
|
@@ -362,10 +362,10 @@ class Thread < Object
|
|
362
362
|
# thread which creating the new thread, or zero for the initial main
|
363
363
|
# thread; higher-priority thread will run more frequently than
|
364
364
|
# lower-priority threads (but lower-priority threads can also run).
|
365
|
-
#
|
365
|
+
#
|
366
366
|
# This is just hint for Ruby thread scheduler. It may be ignored on some
|
367
367
|
# platform.
|
368
|
-
#
|
368
|
+
#
|
369
369
|
# ```ruby
|
370
370
|
# Thread.current.priority #=> 0
|
371
371
|
# ```
|
@@ -374,17 +374,17 @@ class Thread < Object
|
|
374
374
|
# Sets the priority of *thr* to *integer* . Higher-priority threads will
|
375
375
|
# run more frequently than lower-priority threads (but lower-priority
|
376
376
|
# threads can also run).
|
377
|
-
#
|
377
|
+
#
|
378
378
|
# This is just hint for Ruby thread scheduler. It may be ignored on some
|
379
379
|
# platform.
|
380
|
-
#
|
380
|
+
#
|
381
381
|
# ```ruby
|
382
382
|
# count1 = count2 = 0
|
383
383
|
# a = Thread.new do
|
384
384
|
# loop { count1 += 1 }
|
385
385
|
# end
|
386
386
|
# a.priority = -1
|
387
|
-
#
|
387
|
+
#
|
388
388
|
# b = Thread.new do
|
389
389
|
# loop { count2 += 1 }
|
390
390
|
# end
|
@@ -397,16 +397,16 @@ class Thread < Object
|
|
397
397
|
|
398
398
|
# Returns the status of the thread-local “report on exception” condition
|
399
399
|
# for this `thr` .
|
400
|
-
#
|
400
|
+
#
|
401
401
|
# The default value when creating a [Thread](Thread.downloaded.ruby_doc)
|
402
402
|
# is the value of the global flag
|
403
403
|
# [::report\_on\_exception](Thread.downloaded.ruby_doc#method-c-report_on_exception)
|
404
404
|
# .
|
405
|
-
#
|
405
|
+
#
|
406
406
|
# See also
|
407
407
|
# [report\_on\_exception=](Thread.downloaded.ruby_doc#method-i-report_on_exception-3D)
|
408
408
|
# .
|
409
|
-
#
|
409
|
+
#
|
410
410
|
# There is also a class level method to set this for all new threads, see
|
411
411
|
# [::report\_on\_exception=](Thread.downloaded.ruby_doc#method-c-report_on_exception-3D)
|
412
412
|
# .
|
@@ -416,18 +416,18 @@ class Thread < Object
|
|
416
416
|
# kills this `thr` . See
|
417
417
|
# [::report\_on\_exception](Thread.downloaded.ruby_doc#method-c-report_on_exception)
|
418
418
|
# for details.
|
419
|
-
#
|
419
|
+
#
|
420
420
|
# See also
|
421
421
|
# [report\_on\_exception](Thread.downloaded.ruby_doc#method-i-report_on_exception)
|
422
422
|
# .
|
423
|
-
#
|
423
|
+
#
|
424
424
|
# There is also a class level method to set this for all new threads, see
|
425
425
|
# [::report\_on\_exception=](Thread.downloaded.ruby_doc#method-c-report_on_exception-3D)
|
426
426
|
# .
|
427
427
|
def report_on_exception=: (bool report_on_exception) -> untyped
|
428
428
|
|
429
429
|
# Wakes up `thr`, making it eligible for scheduling.
|
430
|
-
#
|
430
|
+
#
|
431
431
|
# ```ruby
|
432
432
|
# a = Thread.new { puts "a"; Thread.stop; puts "c" }
|
433
433
|
# sleep 0.1 while a.status!='sleep'
|
@@ -435,21 +435,21 @@ class Thread < Object
|
|
435
435
|
# a.run
|
436
436
|
# a.join
|
437
437
|
# ```
|
438
|
-
#
|
438
|
+
#
|
439
439
|
# This will produce:
|
440
|
-
#
|
440
|
+
#
|
441
441
|
# ```ruby
|
442
442
|
# a
|
443
443
|
# Got here
|
444
444
|
# c
|
445
445
|
# ```
|
446
|
-
#
|
446
|
+
#
|
447
447
|
# See also the instance method
|
448
448
|
# [wakeup](Thread.downloaded.ruby_doc#method-i-wakeup).
|
449
449
|
def run: () -> Thread
|
450
450
|
|
451
451
|
# Returns the safe level.
|
452
|
-
#
|
452
|
+
#
|
453
453
|
# This method is obsolete because $SAFE is a process global state. Simply
|
454
454
|
# check $SAFE.
|
455
455
|
def safe_level: () -> Integer
|
@@ -457,37 +457,37 @@ class Thread < Object
|
|
457
457
|
def status: () -> (String | bool)?
|
458
458
|
|
459
459
|
# Returns `true` if `thr` is dead or sleeping.
|
460
|
-
#
|
460
|
+
#
|
461
461
|
# ```ruby
|
462
462
|
# a = Thread.new { Thread.stop }
|
463
463
|
# b = Thread.current
|
464
464
|
# a.stop? #=> true
|
465
465
|
# b.stop? #=> false
|
466
466
|
# ```
|
467
|
-
#
|
467
|
+
#
|
468
468
|
# See also [alive?](Thread.downloaded.ruby_doc#method-i-alive-3F) and
|
469
469
|
# [status](Thread.downloaded.ruby_doc#method-i-status).
|
470
470
|
def `stop?`: () -> bool
|
471
471
|
|
472
472
|
# Terminates `thr` and schedules another thread to be run.
|
473
|
-
#
|
473
|
+
#
|
474
474
|
# If this thread is already marked to be killed,
|
475
475
|
# [exit](Thread.downloaded.ruby_doc#method-i-exit) returns the
|
476
476
|
# [Thread](Thread.downloaded.ruby_doc).
|
477
|
-
#
|
477
|
+
#
|
478
478
|
# If this is the main thread, or the last thread, exits the process.
|
479
479
|
def terminate: () -> Thread?
|
480
480
|
|
481
481
|
# Returns `true` if the given string (or symbol) exists as a thread-local
|
482
482
|
# variable.
|
483
|
-
#
|
483
|
+
#
|
484
484
|
# ```ruby
|
485
485
|
# me = Thread.current
|
486
486
|
# me.thread_variable_set(:oliver, "a")
|
487
487
|
# me.thread_variable?(:oliver) #=> true
|
488
488
|
# me.thread_variable?(:stanley) #=> false
|
489
489
|
# ```
|
490
|
-
#
|
490
|
+
#
|
491
491
|
# Note that these are not fiber local variables. Please see
|
492
492
|
# [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D) and
|
493
493
|
# [\#thread\_variable\_get](Thread.downloaded.ruby_doc#method-i-thread_variable_get)
|
@@ -498,15 +498,15 @@ class Thread < Object
|
|
498
498
|
# that these are different than fiber local values. For fiber local
|
499
499
|
# values, please see [\#\[\]](Thread.downloaded.ruby_doc#method-i-5B-5D)
|
500
500
|
# and [\#\[\]=](Thread.downloaded.ruby_doc#method-i-5B-5D-3D).
|
501
|
-
#
|
501
|
+
#
|
502
502
|
# [Thread](Thread.downloaded.ruby_doc) local values are carried along with
|
503
503
|
# threads, and do not respect fibers. For example:
|
504
|
-
#
|
504
|
+
#
|
505
505
|
# ```ruby
|
506
506
|
# Thread.new {
|
507
507
|
# Thread.current.thread_variable_set("foo", "bar") # set a thread local
|
508
508
|
# Thread.current["foo"] = "bar" # set a fiber local
|
509
|
-
#
|
509
|
+
#
|
510
510
|
# Fiber.new {
|
511
511
|
# Fiber.yield [
|
512
512
|
# Thread.current.thread_variable_get("foo"), # get the thread local
|
@@ -515,7 +515,7 @@ class Thread < Object
|
|
515
515
|
# }.resume
|
516
516
|
# }.join.value # => ['bar', nil]
|
517
517
|
# ```
|
518
|
-
#
|
518
|
+
#
|
519
519
|
# The value “bar” is returned for the thread local, where nil is returned
|
520
520
|
# for the fiber local. The fiber is executed in the same thread, so the
|
521
521
|
# thread local values are available.
|
@@ -533,11 +533,11 @@ class Thread < Object
|
|
533
533
|
# Waits for `thr` to complete, using
|
534
534
|
# [join](Thread.downloaded.ruby_doc#method-i-join), and returns its value
|
535
535
|
# or raises the exception which terminated the thread.
|
536
|
-
#
|
536
|
+
#
|
537
537
|
# ```ruby
|
538
538
|
# a = Thread.new { 2 + 2 }
|
539
539
|
# a.value #=> 4
|
540
|
-
#
|
540
|
+
#
|
541
541
|
# b = Thread.new { raise 'something went wrong' }
|
542
542
|
# b.value #=> RuntimeError: something went wrong
|
543
543
|
# ```
|
@@ -545,10 +545,10 @@ class Thread < Object
|
|
545
545
|
|
546
546
|
# Marks a given thread as eligible for scheduling, however it may still
|
547
547
|
# remain blocked on I/O.
|
548
|
-
#
|
548
|
+
#
|
549
549
|
# **Note:** This does not invoke the scheduler, see
|
550
550
|
# [run](Thread.downloaded.ruby_doc#method-i-run) for more information.
|
551
|
-
#
|
551
|
+
#
|
552
552
|
# ```ruby
|
553
553
|
# c = Thread.new { Thread.stop; puts "hey!" }
|
554
554
|
# sleep 0.1 while c.status!='sleep'
|
@@ -559,19 +559,19 @@ class Thread < Object
|
|
559
559
|
def wakeup: () -> Thread
|
560
560
|
|
561
561
|
# Returns the status of the global “abort on exception” condition.
|
562
|
-
#
|
562
|
+
#
|
563
563
|
# The default is `false` .
|
564
|
-
#
|
564
|
+
#
|
565
565
|
# When set to `true`, if any thread is aborted by an exception, the
|
566
566
|
# raised exception will be re-raised in the main thread.
|
567
|
-
#
|
567
|
+
#
|
568
568
|
# Can also be specified by the global $DEBUG flag or command line option
|
569
569
|
# `-d` .
|
570
|
-
#
|
570
|
+
#
|
571
571
|
# See also
|
572
572
|
# [::abort\_on\_exception=](Thread.downloaded.ruby_doc#method-c-abort_on_exception-3D)
|
573
573
|
# .
|
574
|
-
#
|
574
|
+
#
|
575
575
|
# There is also an instance level method to set this for a specific
|
576
576
|
# thread, see
|
577
577
|
# [abort\_on\_exception](Thread.downloaded.ruby_doc#method-i-abort_on_exception)
|
@@ -581,7 +581,7 @@ class Thread < Object
|
|
581
581
|
# When set to `true`, if any thread is aborted by an exception, the
|
582
582
|
# raised exception will be re-raised in the main thread. Returns the new
|
583
583
|
# state.
|
584
|
-
#
|
584
|
+
#
|
585
585
|
# ```ruby
|
586
586
|
# Thread.abort_on_exception = true
|
587
587
|
# t1 = Thread.new do
|
@@ -591,19 +591,19 @@ class Thread < Object
|
|
591
591
|
# sleep(1)
|
592
592
|
# puts "not reached"
|
593
593
|
# ```
|
594
|
-
#
|
594
|
+
#
|
595
595
|
# This will produce:
|
596
|
-
#
|
596
|
+
#
|
597
597
|
# In new thread
|
598
598
|
# prog.rb:4: Exception from thread (RuntimeError)
|
599
599
|
# from prog.rb:2:in `initialize'
|
600
600
|
# from prog.rb:2:in `new'
|
601
601
|
# from prog.rb:2
|
602
|
-
#
|
602
|
+
#
|
603
603
|
# See also
|
604
604
|
# [::abort\_on\_exception](Thread.downloaded.ruby_doc#method-c-abort_on_exception)
|
605
605
|
# .
|
606
|
-
#
|
606
|
+
#
|
607
607
|
# There is also an instance level method to set this for a specific
|
608
608
|
# thread, see
|
609
609
|
# [abort\_on\_exception=](Thread.downloaded.ruby_doc#method-i-abort_on_exception-3D)
|
@@ -619,11 +619,11 @@ class Thread < Object
|
|
619
619
|
|
620
620
|
# Terminates the currently running thread and schedules another thread to
|
621
621
|
# be run.
|
622
|
-
#
|
622
|
+
#
|
623
623
|
# If this thread is already marked to be killed,
|
624
624
|
# [::exit](Thread.downloaded.ruby_doc#method-c-exit) returns the
|
625
625
|
# [Thread](Thread.downloaded.ruby_doc).
|
626
|
-
#
|
626
|
+
#
|
627
627
|
# If this is the main thread, or the last thread, exit the process.
|
628
628
|
def self.exit: () -> untyped
|
629
629
|
|
@@ -634,46 +634,46 @@ class Thread < Object
|
|
634
634
|
def self.fork: (*untyped args) -> untyped
|
635
635
|
|
636
636
|
# Changes asynchronous interrupt timing.
|
637
|
-
#
|
637
|
+
#
|
638
638
|
# *interrupt* means asynchronous event and corresponding procedure by
|
639
639
|
# [\#raise](Thread.downloaded.ruby_doc#method-i-raise),
|
640
640
|
# [\#kill](Thread.downloaded.ruby_doc#method-i-kill), signal trap (not
|
641
641
|
# supported yet) and main thread termination (if main thread terminates,
|
642
642
|
# then all other thread will be killed).
|
643
|
-
#
|
643
|
+
#
|
644
644
|
# The given `hash` has pairs like `ExceptionClass => :TimingSymbol` .
|
645
645
|
# Where the ExceptionClass is the interrupt handled by the given block.
|
646
646
|
# The TimingSymbol can be one of the following symbols:
|
647
|
-
#
|
647
|
+
#
|
648
648
|
# - `:immediate`
|
649
649
|
# Invoke interrupts immediately.
|
650
|
-
#
|
650
|
+
#
|
651
651
|
# - `:on_blocking`
|
652
652
|
# Invoke interrupts while *BlockingOperation* .
|
653
|
-
#
|
653
|
+
#
|
654
654
|
# - `:never`
|
655
655
|
# Never invoke all interrupts.
|
656
|
-
#
|
656
|
+
#
|
657
657
|
# *BlockingOperation* means that the operation will block the calling
|
658
658
|
# thread, such as read and write. On CRuby implementation,
|
659
659
|
# *BlockingOperation* is any operation executed without GVL.
|
660
|
-
#
|
660
|
+
#
|
661
661
|
# Masked asynchronous interrupts are delayed until they are enabled. This
|
662
662
|
# method is similar to sigprocmask(3).
|
663
|
-
#
|
664
|
-
#
|
663
|
+
#
|
664
|
+
#
|
665
665
|
# Asynchronous interrupts are difficult to use.
|
666
|
-
#
|
666
|
+
#
|
667
667
|
# If you need to communicate between threads, please consider to use
|
668
668
|
# another way such as [Queue](https://ruby-doc.org/core-2.6.3/Queue.html)
|
669
669
|
# .
|
670
|
-
#
|
670
|
+
#
|
671
671
|
# Or use them with deep understanding about this method.
|
672
|
-
#
|
673
|
-
#
|
672
|
+
#
|
673
|
+
#
|
674
674
|
# In this example, we can guard from
|
675
675
|
# [\#raise](Thread.downloaded.ruby_doc#method-i-raise) exceptions.
|
676
|
-
#
|
676
|
+
#
|
677
677
|
# Using the `:never` TimingSymbol the
|
678
678
|
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
679
679
|
# exception will always be ignored in the first block of the main thread.
|
@@ -682,7 +682,7 @@ class Thread < Object
|
|
682
682
|
# block we can purposefully handle
|
683
683
|
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
684
684
|
# exceptions.
|
685
|
-
#
|
685
|
+
#
|
686
686
|
# ```ruby
|
687
687
|
# th = Thread.new do
|
688
688
|
# Thread.handle_interrupt(RuntimeError => :never) {
|
@@ -700,18 +700,18 @@ class Thread < Object
|
|
700
700
|
# # ...
|
701
701
|
# th.raise "stop"
|
702
702
|
# ```
|
703
|
-
#
|
703
|
+
#
|
704
704
|
# While we are ignoring the
|
705
705
|
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
706
706
|
# exception, it’s safe to write our resource allocation code. Then, the
|
707
707
|
# ensure block is where we can safely deallocate your resources.
|
708
|
-
#
|
709
|
-
#
|
708
|
+
#
|
709
|
+
#
|
710
710
|
# In the next example, we will guard from the Timeout::Error exception.
|
711
711
|
# This will help prevent from leaking resources when Timeout::Error
|
712
712
|
# exceptions occur during normal ensure clause. For this example we use
|
713
713
|
# the help of the standard library Timeout, from lib/timeout.rb
|
714
|
-
#
|
714
|
+
#
|
715
715
|
# ```ruby
|
716
716
|
# require 'timeout'
|
717
717
|
# Thread.handle_interrupt(Timeout::Error => :never) {
|
@@ -725,18 +725,18 @@ class Thread < Object
|
|
725
725
|
# }
|
726
726
|
# }
|
727
727
|
# ```
|
728
|
-
#
|
728
|
+
#
|
729
729
|
# In the first part of the `timeout` block, we can rely on Timeout::Error
|
730
730
|
# being ignored. Then in the `Timeout::Error => :on_blocking` block, any
|
731
731
|
# operation that will block the calling thread is susceptible to a
|
732
732
|
# Timeout::Error exception being raised.
|
733
|
-
#
|
734
|
-
#
|
733
|
+
#
|
734
|
+
#
|
735
735
|
# It’s possible to stack multiple levels of
|
736
736
|
# [::handle\_interrupt](Thread.downloaded.ruby_doc#method-c-handle_interrupt)
|
737
737
|
# blocks in order to control more than one ExceptionClass and TimingSymbol
|
738
738
|
# at a time.
|
739
|
-
#
|
739
|
+
#
|
740
740
|
# ```ruby
|
741
741
|
# Thread.handle_interrupt(FooError => :never) {
|
742
742
|
# Thread.handle_interrupt(BarError => :never) {
|
@@ -744,11 +744,11 @@ class Thread < Object
|
|
744
744
|
# }
|
745
745
|
# }
|
746
746
|
# ```
|
747
|
-
#
|
748
|
-
#
|
747
|
+
#
|
748
|
+
#
|
749
749
|
# All exceptions inherited from the ExceptionClass parameter will be
|
750
750
|
# considered.
|
751
|
-
#
|
751
|
+
#
|
752
752
|
# ```ruby
|
753
753
|
# Thread.handle_interrupt(Exception => :never) {
|
754
754
|
# # all exceptions inherited from Exception are prohibited.
|
@@ -765,18 +765,18 @@ class Thread < Object
|
|
765
765
|
def self.pass: () -> untyped
|
766
766
|
|
767
767
|
# Returns whether or not the asynchronous queue is empty.
|
768
|
-
#
|
768
|
+
#
|
769
769
|
# Since
|
770
770
|
# [::handle\_interrupt](Thread.downloaded.ruby_doc#method-c-handle_interrupt)
|
771
771
|
# can be used to defer asynchronous events, this method can be used to
|
772
772
|
# determine if there are any deferred events.
|
773
|
-
#
|
773
|
+
#
|
774
774
|
# If you find this method returns true, then you may finish `:never`
|
775
775
|
# blocks.
|
776
|
-
#
|
776
|
+
#
|
777
777
|
# For example, the following method processes deferred asynchronous events
|
778
778
|
# immediately.
|
779
|
-
#
|
779
|
+
#
|
780
780
|
# ```ruby
|
781
781
|
# def Thread.kick_interrupt_immediately
|
782
782
|
# Thread.handle_interrupt(Object => :immediate) {
|
@@ -784,10 +784,10 @@ class Thread < Object
|
|
784
784
|
# }
|
785
785
|
# end
|
786
786
|
# ```
|
787
|
-
#
|
787
|
+
#
|
788
788
|
# If `error` is given, then check only for `error` type deferred events.
|
789
|
-
#
|
790
|
-
#
|
789
|
+
#
|
790
|
+
#
|
791
791
|
# th = Thread.new{
|
792
792
|
# Thread.handle_interrupt(RuntimeError => :on_blocking){
|
793
793
|
# while true
|
@@ -802,10 +802,10 @@ class Thread < Object
|
|
802
802
|
# }
|
803
803
|
# ...
|
804
804
|
# th.raise # stop thread
|
805
|
-
#
|
805
|
+
#
|
806
806
|
# This example can also be written as the following, which you should use
|
807
807
|
# to avoid asynchronous interrupts.
|
808
|
-
#
|
808
|
+
#
|
809
809
|
# flag = true
|
810
810
|
# th = Thread.new{
|
811
811
|
# Thread.handle_interrupt(RuntimeError => :on_blocking){
|
@@ -833,7 +833,7 @@ class Thread < Object
|
|
833
833
|
|
834
834
|
# Stops execution of the current thread, putting it into a “sleep” state,
|
835
835
|
# and schedules execution of another thread.
|
836
|
-
#
|
836
|
+
#
|
837
837
|
# ```ruby
|
838
838
|
# a = Thread.new { print "a"; Thread.stop; print "c" }
|
839
839
|
# sleep 0.1 while a.status!='sleep'
|
@@ -864,13 +864,13 @@ end
|
|
864
864
|
# augment class [Mutex](https://ruby-doc.org/core-2.6.3/Mutex.html).
|
865
865
|
# Using condition variables, it is possible to suspend while in the middle
|
866
866
|
# of a critical section until a resource becomes available.
|
867
|
-
#
|
867
|
+
#
|
868
868
|
# Example:
|
869
|
-
#
|
869
|
+
#
|
870
870
|
# ```ruby
|
871
871
|
# mutex = Mutex.new
|
872
872
|
# resource = ConditionVariable.new
|
873
|
-
#
|
873
|
+
#
|
874
874
|
# a = Thread.new {
|
875
875
|
# mutex.synchronize {
|
876
876
|
# # Thread 'a' now needs the resource
|
@@ -878,7 +878,7 @@ end
|
|
878
878
|
# # 'a' can now have the resource
|
879
879
|
# }
|
880
880
|
# }
|
881
|
-
#
|
881
|
+
#
|
882
882
|
# b = Thread.new {
|
883
883
|
# mutex.synchronize {
|
884
884
|
# # Thread 'b' has finished using the resource
|
@@ -895,7 +895,7 @@ class Thread::ConditionVariable < Object
|
|
895
895
|
|
896
896
|
# Releases the lock held in `mutex` and waits; reacquires the lock on
|
897
897
|
# wakeup.
|
898
|
-
#
|
898
|
+
#
|
899
899
|
# If `timeout` is given, this method returns after `timeout` seconds
|
900
900
|
# passed, even if no other thread doesn't signal.
|
901
901
|
def wait: (Thread::Mutex mutex, ?Integer timeout) -> self
|
@@ -904,18 +904,18 @@ end
|
|
904
904
|
# [Mutex](Mutex) implements a simple semaphore that
|
905
905
|
# can be used to coordinate access to shared data from multiple concurrent
|
906
906
|
# threads.
|
907
|
-
#
|
907
|
+
#
|
908
908
|
# Example:
|
909
|
-
#
|
909
|
+
#
|
910
910
|
# ```ruby
|
911
911
|
# semaphore = Mutex.new
|
912
|
-
#
|
912
|
+
#
|
913
913
|
# a = Thread.new {
|
914
914
|
# semaphore.synchronize {
|
915
915
|
# # access shared resource
|
916
916
|
# }
|
917
917
|
# }
|
918
|
-
#
|
918
|
+
#
|
919
919
|
# b = Thread.new {
|
920
920
|
# semaphore.synchronize {
|
921
921
|
# # access shared resource
|
@@ -951,15 +951,15 @@ end
|
|
951
951
|
# when information must be exchanged safely between multiple threads. The
|
952
952
|
# [Queue](Queue) class implements all the required
|
953
953
|
# locking semantics.
|
954
|
-
#
|
954
|
+
#
|
955
955
|
# The class implements FIFO type of queue. In a FIFO queue, the first
|
956
956
|
# tasks added are the first retrieved.
|
957
|
-
#
|
957
|
+
#
|
958
958
|
# Example:
|
959
|
-
#
|
959
|
+
#
|
960
960
|
# ```ruby
|
961
961
|
# queue = Queue.new
|
962
|
-
#
|
962
|
+
#
|
963
963
|
# producer = Thread.new do
|
964
964
|
# 5.times do |i|
|
965
965
|
# sleep rand(i) # simulate expense
|
@@ -967,7 +967,7 @@ end
|
|
967
967
|
# puts "#{i} produced"
|
968
968
|
# end
|
969
969
|
# end
|
970
|
-
#
|
970
|
+
#
|
971
971
|
# consumer = Thread.new do
|
972
972
|
# 5.times do |i|
|
973
973
|
# value = queue.pop
|
@@ -975,7 +975,7 @@ end
|
|
975
975
|
# puts "consumed #{value}"
|
976
976
|
# end
|
977
977
|
# end
|
978
|
-
#
|
978
|
+
#
|
979
979
|
# consumer.join
|
980
980
|
# ```
|
981
981
|
class Thread::Queue < Object
|
@@ -986,28 +986,28 @@ class Thread::Queue < Object
|
|
986
986
|
def clear: () -> void
|
987
987
|
|
988
988
|
# Closes the queue. A closed queue cannot be re-opened.
|
989
|
-
#
|
989
|
+
#
|
990
990
|
# After the call to close completes, the following are true:
|
991
|
-
#
|
991
|
+
#
|
992
992
|
# - `closed?` will return true
|
993
|
-
#
|
993
|
+
#
|
994
994
|
# - `close` will be ignored.
|
995
|
-
#
|
995
|
+
#
|
996
996
|
# - calling enq/push/\<\< will raise a `ClosedQueueError` .
|
997
|
-
#
|
997
|
+
#
|
998
998
|
# - when `empty?` is false, calling deq/pop/shift will return an object
|
999
999
|
# from the queue as usual.
|
1000
|
-
#
|
1000
|
+
#
|
1001
1001
|
# - when `empty?` is true, deq(false) will not suspend the thread and
|
1002
1002
|
# will return nil. deq(true) will raise a `ThreadError` .
|
1003
|
-
#
|
1003
|
+
#
|
1004
1004
|
# [ClosedQueueError](https://ruby-doc.org/core-2.6.3/ClosedQueueError.html)
|
1005
1005
|
# is inherited from
|
1006
1006
|
# [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html), so
|
1007
1007
|
# that you can break loop block.
|
1008
|
-
#
|
1008
|
+
#
|
1009
1009
|
# Example:
|
1010
|
-
#
|
1010
|
+
#
|
1011
1011
|
# q = Queue.new
|
1012
1012
|
# Thread.new{
|
1013
1013
|
# while e = q.deq # wait for nil to break loop
|
@@ -1030,9 +1030,9 @@ class Thread::Queue < Object
|
|
1030
1030
|
alias enq push
|
1031
1031
|
|
1032
1032
|
# Returns the length of the queue.
|
1033
|
-
#
|
1034
|
-
#
|
1035
|
-
#
|
1033
|
+
#
|
1034
|
+
#
|
1035
|
+
#
|
1036
1036
|
# Also aliased as: [size](Queue.downloaded.ruby_doc#method-i-size)
|
1037
1037
|
def length: () -> Integer
|
1038
1038
|
|
@@ -1040,21 +1040,21 @@ class Thread::Queue < Object
|
|
1040
1040
|
def num_waiting: () -> Integer
|
1041
1041
|
|
1042
1042
|
# Retrieves data from the queue.
|
1043
|
-
#
|
1043
|
+
#
|
1044
1044
|
# If the queue is empty, the calling thread is suspended until data is
|
1045
1045
|
# pushed onto the queue. If `non_block` is true, the thread isn't
|
1046
1046
|
# suspended, and `ThreadError` is raised.
|
1047
|
-
#
|
1048
|
-
#
|
1049
|
-
#
|
1047
|
+
#
|
1048
|
+
#
|
1049
|
+
#
|
1050
1050
|
# Also aliased as: [deq](Queue.downloaded.ruby_doc#method-i-deq),
|
1051
1051
|
# [shift](Queue.downloaded.ruby_doc#method-i-shift)
|
1052
1052
|
def pop: (?bool non_block) -> untyped
|
1053
1053
|
|
1054
1054
|
# Pushes the given `object` to the queue.
|
1055
|
-
#
|
1056
|
-
#
|
1057
|
-
#
|
1055
|
+
#
|
1056
|
+
#
|
1057
|
+
#
|
1058
1058
|
# Also aliased as: [enq](Queue.downloaded.ruby_doc#method-i-enq),
|
1059
1059
|
# [\<\<](Queue.downloaded.ruby_doc#method-i-3C-3C)
|
1060
1060
|
def push: (untyped obj) -> void
|
@@ -1068,7 +1068,7 @@ end
|
|
1068
1068
|
|
1069
1069
|
# This class represents queues of specified size capacity. The push
|
1070
1070
|
# operation may be blocked if the capacity is full.
|
1071
|
-
#
|
1071
|
+
#
|
1072
1072
|
# See [Queue](https://ruby-doc.org/core-2.6.3/Queue.html) for an example
|
1073
1073
|
# of how a [SizedQueue](SizedQueue) works.
|
1074
1074
|
class Thread::SizedQueue < Thread::Queue
|
@@ -1087,13 +1087,13 @@ class Thread::SizedQueue < Thread::Queue
|
|
1087
1087
|
def max=: (Integer max) -> void
|
1088
1088
|
|
1089
1089
|
# Pushes `object` to the queue.
|
1090
|
-
#
|
1090
|
+
#
|
1091
1091
|
# If there is no space left in the queue, waits until space becomes
|
1092
1092
|
# available, unless `non_block` is true. If `non_block` is true, the
|
1093
1093
|
# thread isn't suspended, and `ThreadError` is raised.
|
1094
|
-
#
|
1095
|
-
#
|
1096
|
-
#
|
1094
|
+
#
|
1095
|
+
#
|
1096
|
+
#
|
1097
1097
|
# Also aliased as: [enq](SizedQueue.downloaded.ruby_doc#method-i-enq),
|
1098
1098
|
# [\<\<](SizedQueue.downloaded.ruby_doc#method-i-3C-3C)
|
1099
1099
|
def push: (untyped obj, ?bool non_block) -> void
|