Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
THREADS = 10

1000.times do
  threads = []
  THREADS.times do
    threads << Thread.new do
      sleep
    end
  end

  if (size = Thread.list.size) != THREADS + 1
    raise "wrong! (expected #{THREADS + 1} but was #{size})"
  end

  threads.each do |t|
    Thread.pass until t.status == 'sleep'
    t.wakeup
    t.join
  end
end