I attached a really simple and short script. If you run it, it works as
expected.
If you comment the bottom and uncomment the part directly above, however, it
does not work as expected anymore, it does not execute the block of code
simultanously 10 times anymore - it waits until one socket is finished and
then another thread continues execution.
It seems the socket is not local to the block of code - that maybe why the
other threads don’t touch it until it is closed (when the block of code is
finished) → maybe they all share one socket, but I do not think that is
what is happening.
So if the socket is not local to the block of code, how can I make it local?
I modified your code to include a rescue clause and of course got a
whole load of…
start
failed
done
Then I set the socket to a valid address and got a whole load of
start
done
So it would seem that your code works but perhaps too fast between the
socket open and close for the other thread to get started. So I added a
sleep 5 between the open and close.
So the problem with your code is that the operation of opening the
socket and closing it is too fast to allow another thread to get started
giving the appearance of serial execution.
I modified your code to include a rescue clause and of course got a
whole load of…
start
failed
done
Then I set the socket to a valid address and got a whole load of
start
done
So it would seem that your code works but perhaps too fast between the
socket open and close for the other thread to get started. So I added a
sleep 5 between the open and close.
So the problem with your code is that the operation of opening the
socket and closing it is too fast to allow another thread to get started
giving the appearance of serial execution.
Excellent! Thanks so much! I would have never guessed that it is too fast to
allow another thread to get started.
Thanks again,
-Lars
···
----- Original Message -----
From: “Peter Hickman” peter@semantico.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, January 21, 2003 5:58 PM
Subject: Re: [Threads + Sockets] Strange behavior
I modified your code to include a rescue clause and of course got a
whole load of…
start
failed
done
Then I set the socket to a valid address and got a whole load of
start
done
So it would seem that your code works but perhaps too fast between the
socket open and close for the other thread to get started. So I added a
sleep 5 between the open and close.
So the problem with your code is that the operation of opening the
socket and closing it is too fast to allow another thread to get started
giving the appearance of serial execution.