Bug #3183: "[BUG] The handle is invalid." when working with Threads
http://redmine.ruby-lang.org/issues/show/3183

Author: John Briggs
Status: Open, Priority: Normal
Category: core
ruby -v: ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-mswin32]

Sometimes (about 30% times) when running the following code ruby crashes.

The code:

$threads_alowed = 750;
$threads = []
#Initializing thread objects
$threads_alowed.times{|thread_id|
$threads[thread_id] = {'thread' => Thread.new{}}
puts "thID #{thread_id} initialized"
}

def do_something(thread_id)
wait = rand(300)
print "\nThread #{thread_id} is doing something for #{wait} seconds"
sleep wait
end

while true do
$threads_alowed.times{|thread_id|
status = $threads[thread_id]['thread'].status
if status == false or status == nil
$threads[thread_id]['thread'] = Thread.new(thread_id){do_something(thread_id)}
print ","
end
}
print "."
sleep 0.03
end



The crash:

....
....
....
thID 288 initialized
thID 289 initialized
[BUG] The handle is invalid.

ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-mswin32]

-- control frame ----------
---------------------------
-- Ruby level backtrace information-----------------------------------------

[NOTE]
You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.



Tried Ruby 1.9.1 MinGW and mswin32 with the same result.


----------------------------------------
http://redmine.ruby-lang.org