[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

When threads block

Hans Fugal

9/24/2003 12:46:00 AM

It's difficult to do any serious multi-threaded network programming when
the whole process blocks on system calls like read, write, and select. Is
this on a TODO list somewhere, or should I just accept it as a fact of
life? (and that may mean using a different language.)
8 Answers

nobu.nokada

9/24/2003 6:24:00 AM

0

Hi,

At Wed, 24 Sep 2003 10:16:53 +0900,
Hans Fugal wrote:
> It''s difficult to do any serious multi-threaded network programming when
> the whole process blocks on system calls like read, write, and select. Is
> this on a TODO list somewhere, or should I just accept it as a fact of
> life? (and that may mean using a different language.)

What''s your platform?

If you use Windows, it''s a known problem but hard to fix with
current thread implementation.

--
Nobu Nakada

Thomas Sondergaard

9/24/2003 9:27:00 AM

0

> If you use Windows, it''s a known problem but hard to fix with
> current thread implementation.

When will we get a new thread implementation, then? :-)

Seriously, could you outline how these things are implemented on other
platforms to avoid blocking the entire process? Why can''t this trick be used
on the windows platform? I''d like to help if I can in any way.

Another question - is true thread safety on the TODO list for ruby? Oh and
this begs the third question: Is there a release plan for ruby? I would love
to know what kind of goodies I can expect for future releases?

Cheers,

Thomas


Hans Fugal

9/24/2003 1:14:00 PM

0

On Tue, 23 Sep 2003 18:45:40 -0600, Hans Fugal wrote:

> It''s difficult to do any serious multi-threaded network programming when
> the whole process blocks on system calls like read, write, and select. Is
> this on a TODO list somewhere, or should I just accept it as a fact of
> life? (and that may mean using a different language.)

Ok, I jumped the gun just a little. On linux /most/ things don''t block.
But /some/ things do. e.g.

thread = Thread.new do
fifo = File.open("fifo","r")
l = fifo.readline
puts "#{Time.new} #{l}"
end

puts "#{Time.new} bar"
thread.join

Will block the entire process until the fifo is open. The following
variation does not block the entire process, though:

fifo = File.open("fifo","r")
thread = Thread.new do
l = fifo.readline
puts "#{Time.new} #{l}"
end

puts "#{Time.new} bar"
thread.join

I say "most" because that''s what the wise ones on #ruby-lang said, and
indeed were surprised to see I had a counter example.

Is there a list of these sorts of things? I need to know what to expect if
I''m going to be able to use ruby for this (soft) real-time application.

gabriele renzi

9/24/2003 4:33:00 PM

0

il Wed, 24 Sep 2003 11:26:47 +0200, "Thomas Sondergaard"
<thomas@FirstNameGoesHereSondergaard.com> ha scritto::

>> If you use Windows, it''s a known problem but hard to fix with
>> current thread implementation.
>
>When will we get a new thread implementation, then? :-)
>
>Seriously, could you outline how these things are implemented on other
>platforms to avoid blocking the entire process? Why can''t this trick be used
>on the windows platform? I''d like to help if I can in any way.

The problem should be related to windows'' select().
On *nix IO stuff is transparently put in a select, and ruby takes care
of giving a little time to every thread when select gives them output.
On windows this won''t work cause select() just accepts socket
descriptor. I wonder if these works in python.
And is WaitForMultipleObjects() useful someway ?

>Another question - is true thread safety on the TODO list for ruby? Oh and
>this begs the third question: Is there a release plan for ruby? I would love
>to know what kind of goodies I can expect for future releases?

wait for Rite (ruby 2.0)


nobu.nokada

9/24/2003 11:53:00 PM

0

Hi,

At Wed, 24 Sep 2003 22:38:58 +0900,
Hans Fugal wrote:
> Ok, I jumped the gun just a little. On linux /most/ things don''t block.
> But /some/ things do. e.g.
>
> thread = Thread.new do
> fifo = File.open("fifo","r")
> l = fifo.readline
> puts "#{Time.new} #{l}"
> end
>
> puts "#{Time.new} bar"
> thread.join

You can use IO::NONBLOCK with IO::RDONLY instead of "r".

> Is there a list of these sorts of things? I need to know what to expect if
> I''m going to be able to use ruby for this (soft) real-time application.

File#flock, and some Socket methods do. Use resolv-replace.rb
for the latter.

--
Nobu Nakada

Lothar Scholz

9/25/2003 12:16:00 AM

0

Hello gabriele,

Wednesday, September 24, 2003, 5:39:20 PM, you wrote:

gr> The problem should be related to windows'' select().
gr> On *nix IO stuff is transparently put in a select, and ruby takes care
gr> of giving a little time to every thread when select gives them output.
gr> On windows this won''t work cause select() just accepts socket
gr> descriptor. I wonder if these works in python.
gr> And is WaitForMultipleObjects() useful someway ?

It''s a joke right ?

Every serious windows programming books warns you to not use ''select''
on a window plattform. Using WASSelect is the normal way. It is much
better then the UNIX API and integrates perfect into the windows
environment. But a new implementation should not use them either.
The best is to use asynchron system calls that calls back when data
is available, it is much faster then the LINUX ip stack implementation.

--
Best regards,
Lothar mailto:mailinglists@scriptolutions.com


gabriele renzi

9/25/2003 8:21:00 PM

0

il Thu, 25 Sep 2003 09:15:50 +0900, Lothar Scholz
<mailinglists@scriptolutions.com> ha scritto::

>gr> And is WaitForMultipleObjects() useful someway ?
>
>It''s a joke right ?
>
>Every serious windows programming books warns you to not use ''select''
>on a window plattform.

That''s sure. I never ever read a windows programming book, this may
matter :)
Actually, I just wrote some win code for an OS course and at most used
3 syscall ..

>Using WASSelect is the normal way.
Is''nt WSASelect even stuck to FD_SET==array of sockets?

> It is much
>better then the UNIX API and integrates perfect into the windows
>environment.

Sure it does, but well, ruby is mostly developed on unix :/


anyway, I was simply referring to Message-Id:
<200309240558.h8O5wE2s021288@sharui.nakada.kanuma.tochigi.jp>

Lothar Scholz

9/26/2003 1:26:00 PM

0

Hello gabriele,

>>Using WASSelect is the normal way.
gr> Is''nt WSASelect even stuck to FD_SET==array of sockets?

No. Its working with GUI messages.

>> It is much
>>better then the UNIX API and integrates perfect into the windows
>>environment.

gr> Sure it does, but well, ruby is mostly developed on unix :/

But it''s a "very high level language" and it fallsback to extremely
low level plattform dependent network code. That''s a design decision i don''t
understand. It''s okay to wrap this, but higher modules like the HTTP,
FTP protocol shouldn''t be based on a ''select'' like model.


--
Best regards,
Lothar mailto:mailinglists@scriptolutions.com