我想把标签放在线程上
a = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
tab1 = Hash[*a.group_by{ |v| v }.flat_map{ |k, v| [k, v.size] }]
puts t1=Thread.new{tab1}
puts t2=Thread.new{tab1}
t1.join
t2.join
答案 0 :(得分:0)
你的问题不清楚。此?
a = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
tab1 = proc { Hash[a.group_by{ |v| v }.map{ |k, v| [k, v.size] }] }
t1 = Thread.new(&tab1)
t2 = Thread.new(&tab1)
p t1.value
p t2.value