ruby多线程问题

本人在学习Ruby线程时,有一个问题搞不明白。
[code="ruby"]count = 0
thread_list = []

10.times do |i|
thread_list[i] = Thread.new do
sleep(0.5)
Thread.current["my_current"] = count
count += 1
end
end

sleep(1)
puts count

thread_list.each do |thread|
print "my index is ", thread_list.index(thread), "; "; thread.join; print "my count is ", thread["my_current"], ", \n"
end

puts count[/code]
以上代码在运行时,在第6行存在的时候,会出现以下结果
[list]
10
my index is 0; my count is 9,
my index is 1; my count is 8,
my index is 2; my count is 7,
my index is 3; my count is 6,
my index is 4; my count is 5,
my index is 5; my count is 4,
my index is 6; my count is 3,
my index is 7; my count is 2,
my index is 8; my count is 1,
my index is 9; my count is 0,
10
[/list]

请问为什么会造成index和count的顺序反序的原因。
谢谢。
[b]问题补充:[/b]
感谢RednaxelaFX的回答。
我把那段代码放到JRuby下运行,得到结果的确不是每回都一样的。
关于你所说的 不应该依赖Ruby某个版本的线程调度的实现细节。
是不是自己写逻辑来处理这些线程之间的同步?

umm……你不应该依赖Ruby某个版本的线程调度的实现细节。
在Ruby 1.9和JRuby上跑那段代码得到的结果都(经常)是:
10
my index is 0; my count is 2,
my index is 1; my count is 1,
my index is 2; my count is 0,
my index is 3; my count is 3,
my index is 4; my count is 4,
my index is 5; my count is 5,
my index is 6; my count is 6,
my index is 7; my count is 7,
my index is 8; my count is 8,
my index is 9; my count is 9,
10
(大量测试的途中出现过这些样的:
10
my index is 0; my count is 2,
my index is 1; my count is 1,
my index is 2; my count is 0,
my index is 3; my count is 3,
my index is 4; my count is 4,
my index is 5; my count is 5,
my index is 6; my count is 6,
my index is 7; my count is 7,
my index is 8; my count is 8,
my index is 9; my count is 9,
10

10
my index is 0; my count is 1,
my index is 1; my count is 0,
my index is 2; my count is 2,
my index is 3; my count is 3,
my index is 4; my count is 4,
my index is 5; my count is 5,
my index is 6; my count is 6,
my index is 7; my count is 7,
my index is 8; my count is 8,
my index is 9; my count is 9,
10

如果你需要保证一些事情的顺序,像是说你的程序满足生产者-消费者模型,哲学家用餐模型之类的,那自己做好同步是必要的。
但在使用线程和考虑同步之前,可以先看看你的程序是否真的需要使用线程。见过不少程序开了好几个线程但其实都在互相等着,总是只有一个线程真的在干活然后把结果送给下一个线程。那样的话就没有使用线程的必要了。
根据你的使用场景考虑一下吧 ^ ^