Concurrency Coordination Reports
Thread Value Coordination Report
Run a bounded worker thread, collect its return value, and report a size label for the settled result.
Thread Value Coordination Report
thread_value_coordination_report.rb
seed =
worker = Thread.new do
total = 0
seed.times do |step|
total += step + 1
end
total
end
result = worker.value
finished = worker.status == false
status = if result <= 3
"small"
elsif result <= 12
"mid"
else
"large"
end
puts "seed=#{seed}"
puts "finished=#{finished}"
puts "result=#{result}"
puts "status=#{status}"
seed =
worker = Thread.new do
total = 0
seed.times do |step|
total += step + 1
end
total
end
result = worker.value
finished = worker.status == false
status = if result <= 3
"small"
elsif result <= 12
"mid"
else
"large"
end
puts "seed=#{seed}"
puts "finished=#{finished}"
puts "result=#{result}"
puts "status=#{status}"
seed =
worker = Thread.new do
total = 0
seed.times do |step|
total += step + 1
end
total
end
result = worker.value
finished = worker.status == false
status = if result <= 3
"small"
elsif result <= 12
"mid"
else
"large"
end
puts "seed=#{seed}"
puts "finished=#{finished}"
puts "result=#{result}"
puts "status=#{status}"
thread value
`Thread#value` joins a worker and returns the value of its block, so reading the settled result reports the finished state without leaving a background thread running.