require 'thread'

i = 0
threads = []
while i < 100000
    threads << Thread.new(i) { |i|
        puts "This is thread #{i}"
    }
    i += 1
end
threads.each do |t|; t.join; end

---

I read an article about weightless threads in Python
(http://www-106.ibm.com/developerworks/library/l-pythrd.html) that
said it could create 100,000 weightless threads on a 366MHz Pentium II
with 64 MB of RAM in 10 seconds, so I was curious to see how Ruby's
threads (Thread class) would compare.

It looked like each thread in Ruby would take up about 15k of RAM,
which would make 100,000 threads kill my machine (Athlon AMD 1GHz with
512 MB of RAM) due to insufficient RAM to hold everything. I also
wrote another program that would sleep(1000) in each thread, and
noticed that as the number of threads got higher, the program was
slower to create new threads (it slowed to a crawl at around 3000
threads).

It looks like on hardware like mine, Ruby could handle the overhead of
1000 threads with no problem, though.