Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9861d8e

Browse files
committed
20200110
1 parentc428249 commit9861d8e

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

‎README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,13 +2274,23 @@ puts "==== I am the main thread."
22742274
# thread.join # Try to uncomment these two lines to see the differences.
22752275
# puts "==== after thread.join"
22762276
```
2277-
You will find that if there is no`thread.join`, you can only see`==== I am the main thread.` in console.
2277+
You will find that if there is no`thread.join`, you can see
2278+
```log
2279+
==== I am the main thread.
2280+
==== after thread.join
2281+
~~~~ 0
2282+
~~~~ 1
2283+
~~~~ 2
2284+
```
2285+
in console.
22782286

22792287
After you added`thread.join`, you can see:
2280-
```ruby
2288+
```log
2289+
==== I am the main thread.
2290+
~~~~ 0
22812291
~~~~ 1
22822292
~~~~ 2
2283-
~~~~3
2293+
==== after thread.join
22842294
````
22852295
in console.
22862296
@@ -2289,26 +2299,36 @@ Try to run `test_thread_join2.rb`.
22892299
```ruby
22902300
# ./test_thread_join2.rb
22912301
arr = [
2292-
Thread.new { sleep 1 },
22932302
Thread.new do
2294-
sleep 5
2303+
puts 'I am arr[0]'
2304+
sleep 1
2305+
puts 'After arr[0]'
2306+
end,
2307+
Thread.new do
22952308
puts 'I am arr[1]'
2309+
sleep 5
2310+
puts 'After arr[1]'
22962311
end,
2297-
Thread.new { sleep 8}
2312+
Thread.new do
2313+
puts 'I am arr[2]'
2314+
sleep 8
2315+
puts 'After arr[2]'
2316+
end
22982317
]
22992318
2300-
puts Thread.list.size # returns 4 (including the main thread)
2319+
puts"Thread.list.size: #{Thread.list.size}" # returns 4 (including the main thread)
23012320
23022321
sleep 2
23032322
23042323
arr.each { |thread| puts "~~~~~ #{thread}" }
23052324
2306-
puts Thread.list.size # returns 3 (because arr[0] is dead)
2325+
puts"Thread.list.size: #{Thread.list.size}" # returns 3 (because arr[0] is dead)
23072326
2308-
#arr[1].join # uncomment to see differences
2327+
arr[1].join # uncomment to see differences
23092328
23102329
arr.each { |thread| puts "~~~~~ #{thread}" }
23112330
2331+
sleep 7
23122332
puts "Exit main thread"
23132333
```
23142334

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp