我正在试验 ruby 中的多线程。我运行了这段同时运行 3 个线程的代码(ruby threads.rb
在我的终端中):
arr = []
arr.push(Thread.new do
1000000.times do |i|
puts "thread 1"
end
end)
arr.push(Thread.new do
1000000.times do |i|
puts "thread 2"
end
end)
arr.push(Thread.new do
1000000.times do |i|
puts "thread 3"
end
end)
arr.each {|t| t.join}
我现在htop
在终端的树视图中运行,看看我是否真的可以看到 3 个不同的线程:
我认为线程threads.rb 是突出显示的线程正下方的行,但我看不到我的三个启动线程作为threads.rb 进程的分支。红宝石线程与使用htop 显示的线程和进程无关吗?有没有办法可视化在我的 threads.rb 进程中运行的不同 ruby 线程。