#puts "definindo taskset -c -p 1 #{Process.pid}"
#`taskset -c -p 2 #{Process.pid}`

inicio_geral = Time.now
t1 = Thread.new do 
  Thread.current[:target] = 0
  while true
    Thread.current[:target] += 1 
  end
end

10.downto(0) do |i|
  inicio = Time.now
  Kernel.sleep(1)
  puts "faltando #{i} segundos (#{Time.now - inicio})"
end

puts "zerando thread com contagem em #{t1[:target]}"
t1[:target] = 0

t2 = Thread.new do
  Thread.current[:target] = 0
  while true
    Thread.current[:target] += 1
  end
end

t3 = Thread.new do
  Thread.current[:target] = 0
  while true
    Thread.current[:target] += 1
  end
end
10.times do
    puts "primeira #{t1[:target]}"
    puts "segunda  #{t2[:target]}"
    puts "terceira #{t3[:target]}"
    puts "\n\n"
    sleep(1)
end
total = t1[:target].to_i + t2[:target].to_i + t3[:target].to_i
puts "total #{total}"
puts "media #{total/(Time.now - inicio_geral).to_i}"
puts "\n\n"
puts "time #{Time.now - inicio_geral}"

