From: John Briggs on
Hi!

I am new to this forum so this is my first post.

I have Ruby 1.9.1 on Windows 7 and I am trying to make a program that
will do some jobs in threads.
A simplified version of what I want to do would look like this:

$threads_alowed = 700;
$threads = []

$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

It seems to work but often I get the following error:


[BUG] The handle is invalid.

ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

-- 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.


and all the script crashes.

I tried to run the same script on CentOS and it is working without
problems, but I can not stick to just one OS. I need this script to work
on every OS that Ruby runs on.

So my question is: Does anybody know how to get rid of this error on
windows or maybe any workaround and what this error mean?
--
Posted via http://www.ruby-forum.com/.

From: Chuck Remes on
On Apr 21, 2010, at 9:25 AM, John Briggs wrote:
> It seems to work but often I get the following error:
>
>
> [BUG] The handle is invalid.
>
> ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]
>
> -- 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.
>
>
> and all the script crashes.
>
> I tried to run the same script on CentOS and it is working without
> problems, but I can not stick to just one OS. I need this script to work
> on every OS that Ruby runs on.
>
> So my question is: Does anybody know how to get rid of this error on
> windows or maybe any workaround and what this error mean?

You might want to try the release from ruby-lang.org [1]. It is built differently than the version you are running (I assume you got it from rubyinstaller.org). The Ruby from ruby-lang is built using Microsoft's development tools and calls into Win32 APIs directly. The version from rubyinstaller.org is built against MinGW which provides a POSIX emulation layer on top of most Windows APIs. As a result, the mingw version exercises more UNIX code paths than it does Windows code paths in the 1.9.x source.

That said, you should still submit your code example as a bug report against the 1.9.x codebase.

cr

[1] http://www.ruby-lang.org/en/downloads/

From: Luis Lavena on
On Apr 21, 11:39 am, Chuck Remes <cremes.devl...(a)mac.com> wrote:
> [...]
>
> > So my question is: Does anybody know how to get rid of this error on
> > windows or maybe any workaround and what this error mean?
>
> You might want to try the release from ruby-lang.org [1]. It is built differently than the version you are running (I assume you got it from rubyinstaller.org). The Ruby from ruby-lang is built using Microsoft's development tools and calls into Win32 APIs directly. The version from rubyinstaller.org is built against MinGW which provides a POSIX emulation layer on top of most Windows APIs. As a result, the mingw version exercises more UNIX code paths than it does Windows code paths in the 1.9.x source.
>

Your statements are incorrect.

You're confusing MinGW with cygwin.

MinGW provides minimal set of GNU tools for Windows (that is the
meaning of MinGW acronym)

It links and compiles against Win32API, there is no emulation layer of
POSIX functionality.

Please research before state that type of answers as it might confuse
and alienate users of Ruby on Windows platform.

As for the original reporter of the issue:

You're trying to "print" to STDOUT from different threads, which will
produce a race conditions and depending other operations you're
performing, highly likely will crash.

Add to that, you're trying to spawn 700 threads, which spawned quickly
will generate overhead and highly likely you're exhausting resources
in the process (since you don't get a backtrace of your test script)

But more concrete, exhausting of resources could be associated with
available descriptors that Ruby 1.9 has been compiled for.

--
Luis Lavena
From: Chuck Remes on
On Apr 21, 2010, at 2:00 PM, Luis Lavena wrote:

> On Apr 21, 11:39 am, Chuck Remes <cremes.devl...(a)mac.com> wrote:
>> [...]
>>
>>> So my question is: Does anybody know how to get rid of this error on
>>> windows or maybe any workaround and what this error mean?
>>
>> You might want to try the release from ruby-lang.org [1]. It is built differently than the version you are running (I assume you got it from rubyinstaller.org). The Ruby from ruby-lang is built using Microsoft's development tools and calls into Win32 APIs directly. The version from rubyinstaller.org is built against MinGW which provides a POSIX emulation layer on top of most Windows APIs. As a result, the mingw version exercises more UNIX code paths than it does Windows code paths in the 1.9.x source.
>>
>
> Your statements are incorrect.
>
> You're confusing MinGW with cygwin.
>
> MinGW provides minimal set of GNU tools for Windows (that is the
> meaning of MinGW acronym)
>
> It links and compiles against Win32API, there is no emulation layer of
> POSIX functionality.
>
> Please research before state that type of answers as it might confuse
> and alienate users of Ruby on Windows platform.

Oops, my mistake. Now I know the correct answer for next time.

cr