[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[nuby] about ruby multithreading

Lionel Thiry

12/3/2004 3:42:00 PM

Hello!
I need help:
Is Ruby multithreading cooperative or preemptive?

I mean: am I forced to abuse of Thread.pass in (every heavy) threads or
may I just assume the ruby interpreter will commute threads itself?

Another question:
Is Ruby multithreading blocked by system calls?

Like for example when calling system("command line").

If "no" to any of these questions, can I expect Ruby to work that way
someday?

Thanks for the help,
Lionel Thiry
9 Answers

James Gray

12/3/2004 3:55:00 PM

0

On Dec 3, 2004, at 9:47 AM, Lionel Thiry wrote:

> Hello!
> I need help:
> Is Ruby multithreading cooperative or preemptive?

Preemptive.

> I mean: am I forced to abuse of Thread.pass in (every heavy) threads
> or may I just assume the ruby interpreter will commute threads itself?

Yes, ruby will handle thread scheduling.

> Another question:
> Is Ruby multithreading blocked by system calls?
>
> Like for example when calling system("command line").

Hmm, good question. I assume yes, but let's let someone who knows
better than me answer this one... ;)

James Edward Gray II



Michael Neumann

12/3/2004 4:12:00 PM

0

James Edward Gray II wrote:
> On Dec 3, 2004, at 9:47 AM, Lionel Thiry wrote:
>
>> Hello!
>> I need help:
>> Is Ruby multithreading cooperative or preemptive?
>
>
> Preemptive.
>
>> I mean: am I forced to abuse of Thread.pass in (every heavy) threads
>> or may I just assume the ruby interpreter will commute threads itself?
>
>
> Yes, ruby will handle thread scheduling.
>
>> Another question:
>> Is Ruby multithreading blocked by system calls?
>>
>> Like for example when calling system("command line").
>
>
> Hmm, good question. I assume yes, but let's let someone who knows
> better than me answer this one... ;)

Yes:

Thread.new {
loop do
sleep 1
p "."
end
}

system("sleep 10000")

And for IO operations, this is true, too. Ruby does not block on
read/write as it internally uses select.

Regards,

Michael


Lionel Thiry

12/3/2004 4:28:00 PM

0

Michael Neumann wrote:
> James Edward Gray II wrote:
>
>> On Dec 3, 2004, at 9:47 AM, Lionel Thiry wrote:
>>
>>> Hello!
>>> I need help:
>>> Is Ruby multithreading cooperative or preemptive?
>>
>>
>>
>> Preemptive.
>>
>>> I mean: am I forced to abuse of Thread.pass in (every heavy) threads
>>> or may I just assume the ruby interpreter will commute threads itself?
>>
>>
>>
>> Yes, ruby will handle thread scheduling.
>>
>>> Another question:
>>> Is Ruby multithreading blocked by system calls?
>>>
>>> Like for example when calling system("command line").
>>
>>
>>
>> Hmm, good question. I assume yes, but let's let someone who knows
>> better than me answer this one... ;)
>
>
> Yes:
>
> Thread.new {
> loop do
> sleep 1
> p "."
> end
> }
>
> system("sleep 10000")
>
> And for IO operations, this is true, too. Ruby does not block on
> read/write as it internally uses select.
>
> Regards,
>
> Michael
>
>

Thanks all,
Lionel

Eric Hodel

12/3/2004 5:59:00 PM

0

On 03 Dec 2004, at 08:12, Michael Neumann wrote:

> James Edward Gray II wrote:
>> On Dec 3, 2004, at 9:47 AM, Lionel Thiry wrote:
>> Hmm, good question. I assume yes, but let's let someone who knows
>> better than me answer this one... ;)
>
> Yes:
>
> Thread.new {
> loop do
> sleep 1
> p "."
> end
> }
>
> system("sleep 10000")
>
> And for IO operations, this is true, too. Ruby does not block on
> read/write as it internally uses select.

No, system does not block other ruby threads.

$ cat x.rb
STDOUT.sync = true

Thread.new {
loop do
sleep 1
puts Time.now
end
}

system("sleep 10")

$ ruby -v x.rb
ruby 1.8.2 (2004-11-06) [powerpc-darwin7.6.0]
Fri Dec 03 09:57:47 PST 2004
Fri Dec 03 09:57:48 PST 2004
Fri Dec 03 09:57:49 PST 2004
Fri Dec 03 09:57:50 PST 2004
Fri Dec 03 09:57:51 PST 2004
Fri Dec 03 09:57:52 PST 2004
Fri Dec 03 09:57:53 PST 2004
Fri Dec 03 09:57:54 PST 2004
Fri Dec 03 09:57:55 PST 2004
$



Lionel Thiry

12/4/2004 4:01:00 PM

0

> No, system does not block other ruby threads.
Thanks for the remark... I was a bit confused about my interpretation of
the answer, and I could not test system("sleep 10000") on my windows2k
to see how it works.

>
> $ cat x.rb
> STDOUT.sync = true
I didn't know that stuff!
It's interesting, where is that documented?

>
> Thread.new {
> loop do
> sleep 1
> puts Time.now
> end
> }
>
> system("sleep 10")
>
> $ ruby -v x.rb
> ruby 1.8.2 (2004-11-06) [powerpc-darwin7.6.0]
> Fri Dec 03 09:57:47 PST 2004
> Fri Dec 03 09:57:48 PST 2004
> Fri Dec 03 09:57:49 PST 2004
> Fri Dec 03 09:57:50 PST 2004
> Fri Dec 03 09:57:51 PST 2004
> Fri Dec 03 09:57:52 PST 2004
> Fri Dec 03 09:57:53 PST 2004
> Fri Dec 03 09:57:54 PST 2004
> Fri Dec 03 09:57:55 PST 2004
> $
Thanks for the help,
Lionel Thiry

Eric Hodel

12/4/2004 11:38:00 PM

0

On 04 Dec 2004, at 08:02, Lionel Thiry wrote:

>> No, system does not block other ruby threads.
> Thanks for the remark... I was a bit confused about my interpretation
> of the answer, and I could not test system("sleep 10000") on my
> windows2k to see how it works.

Maybe only on (some) windows builds it blocks? I no longer have a
windows machine handy to test these things on.

>> $ cat x.rb
>> STDOUT.sync = true
> I didn't know that stuff!
> It's interesting, where is that documented?

ri has it:

$ ri IO#sync
---------------------------------------------------------------- IO#sync
ios.sync => true or false
------------------------------------------------------------------------
Returns the current ``sync mode'' of _ios_. When sync mode is true,
all output is immediately flushed to the underlying operating
system and is not buffered by Ruby internally. See also +IO#fsync+.

f = File.new("testfile")
f.sync #=> false
$ ri IO#sync=
--------------------------------------------------------------- IO#sync=
ios.sync = boolean => boolean
------------------------------------------------------------------------
Sets the ``sync mode'' to +true+ or +false+. When sync mode is
true, all output is immediately flushed to the underlying operating
system and is not buffered internally. Returns the new state. See
also +IO#fsync+.

f = File.new("testfile")
f.sync = true

_(produces no output)_



Lionel Thiry

12/6/2004 4:05:00 PM

0

Eric Hodel wrote:
> On 04 Dec 2004, at 08:02, Lionel Thiry wrote:
>
>>> No, system does not block other ruby threads.
>>
>> Thanks for the remark... I was a bit confused about my interpretation
>> of the answer, and I could not test system("sleep 10000") on my
>> windows2k to see how it works.
>
>
> Maybe only on (some) windows builds it blocks? I no longer have a
> windows machine handy to test these things on.
I haven't correcly explained. On my w2k, the sleep command simply
doesn't exists, then I couldn't test that ruby code. And I have no clue
about a substitute.

>
>>> $ cat x.rb
>>> STDOUT.sync = true
>>
>> I didn't know that stuff!
>> It's interesting, where is that documented?
>
>
> ri has it:
>
> $ ri IO#sync
Oh yes! I forgot STDOUT was simply an IO object.
But why do we need it here?

Lionle Thiry

Eric Hodel

12/6/2004 8:08:00 PM

0


On 06 Dec 2004, at 08:07, Lionel Thiry wrote:

> Eric Hodel wrote:
>> On 04 Dec 2004, at 08:02, Lionel Thiry wrote:
>>>> No, system does not block other ruby threads.
>>>
>>> Thanks for the remark... I was a bit confused about my
>>> interpretation of the answer, and I could not test system("sleep
>>> 10000") on my windows2k to see how it works.
>> Maybe only on (some) windows builds it blocks? I no longer have a
>> windows machine handy to test these things on.
> I haven't correcly explained. On my w2k, the sleep command simply
> doesn't exists, then I couldn't test that ruby code. And I have no
> clue about a substitute.

Yes, I know.

>>>> $ cat x.rb
>>>> STDOUT.sync = true
>>>
>>> I didn't know that stuff!
>>> It's interesting, where is that documented?
>> ri has it:
>> $ ri IO#sync
> Oh yes! I forgot STDOUT was simply an IO object.
> But why do we need it here?

To be explicit and to behave as expected when you run it on a machine
with sleep. Without it, the OS may buffer the printing, and flush when
the program exits (all 10 lines at once). This would give the
appearance that system() blocked the Ruby thread.



Bob

3/30/2012 8:36:00 AM

0

On Sun, 12 Feb 2012 21:56:48 -0800 (PST),
*ANONYMOUS* CRAVEN COWARD, Who Lacked the
Courage of His Convictions to Post under His REAL,
FULL, and Easily-Verifiable Name as Many People in
Here Do Because They Do NOT support LOATHSOME
Agendas, "Dino" <whatever@homemail.com> wrote:
> "Kat" <ladyas...@comcast.net> wrote:
>> "Dino" <whate...@homemail.com> wrote:
>>> (?`?.? ?Craig Chilton ??.???)
>>> <http://www.TravelForP... wrote:
>>>> "Dino" <whate...@homemail.com> wrote...


>>>> ? ? ?...NOTHING *truthful*.
>>>>
>>>>
>>>> Previous post follows:

>>>> ? ? ? ? ? = = = = = = = = = = = = = = = = = = = =

>>>> On Sat, 11 Feb 2012 19:24:06 -0800 (PST),
>>>> "Dino" <whate...@homemail.com> wrote:
>>>>> ?(?`?.? ?Craig Chilton ??.???)
>>>>> ?<http://www.TravelForP... wrote:
>>>>>> "Dino" <whate...@homemail.com> wrote:
>>>>>>> ?(?`?.? ?Craig Chilton ??.???)
>>>>>>> ?<http://www.TravelForP... wrote:
>>>>>>>> ?Dino <whate...@homemail.com> wrote:
>>>>>>>>> ?"Kat" <ladyas...@comcast.net> wrote:
>>>>>>>>>> "Nancy" <nw...@live.com> wrote:


>>>>>>>>>> ? ?For the record? I support a woman's right to choose but it doesn't
>>>>>>>>>> reflect what I personally would do. I just don't think that people
>>>>>>>>>> should have the right to control the goings on of my uterus.

>>>>>>>>>> ? ? So kindly take your hateful, nasty, bitchy little cuts and jabs to
>>>>>>>>>> yourself. I'm not interested in passive aggressive cat fights with a
>>>>>>>>>> religious bigot.

>>>>>>>>> ? ? You wouldn't be calling her names and calling her a bitch, would
>>>>>>>>> you? I do believe you got very upset at names you were called.

>>>>>>>> ? ? Outspoken people EARN the *accurate* descriptors that HONEST
>>>>>>>> people apply to them. ?Those descriptors denote FAIRNESS when
>>>>>>>> applied to egalitarians, and HATEFULNESS when applied to bigots.
>>>>>>>> ? ? INTELLIGENT people don't let themselves be publicly known as
>>>>>>>> irrational and hateful ignoramuses by publicly supporting BIGOTED
>>>>>>>> agendas. ?It's their call. ?They get what they DESERVE.

>>>>>>> ? ?Hmmm,
>>>>>>>
>>>>>>> ? ?If Kat openly spoke out against abortion, would you b calling her
>>>>>>> intelligent, honest, or fair?

>>>>>> ? ? ?ANY person who would prove him/herself to be an ANTI-Choice
>>>>>> bigot would receive well-deserved condemnation from me. ?But "Kat"
>>>>>> is an egalitarian, so your question is pointless.

>>>>> ? ? ?My question went unanswered.

>>>> ? ? ?Because it was a DUMB question.

>>>>> ? ? ?If she openly spoke out against abortion, would you be calling her
>>>>> intelligent, honest or fair?

>>>> ? ? I would call her the OPPOSITE of ALL of those. ?ALL Anti-Choicers
>>>> are pond scum, and I would regard them as such. ?But since she is
>>>> PRO-Choice -- that is -- as I told you before -- a moot question. Some-
>>>> thing I don't have to be concerned with.

>>> So you lied.

I never lie in my posts, and this was no exception.

>>> You would call her the opposite if she simply "spoke out" against
>>> abortion. You are for censorship and telling women what they can
>>> and can not say.

>> I interpreted what he was saying as this:
>>
>> "speaking out" = stating you are anti-choice

> Regardless, speaking out or stating. Same thing.
>
> Women have the right to speak freely. And you seen...

[[[ ILLITERACY is *commonly* found in lowlifes
who are *ignorant* enough to be bigots. ]]]

> ...what Craig will say about women who speak out (state) that they
> are against abortion. Suddenly they are imbeciles or ignorant or bigots.

Yep. They are perfectly FREE to be QUISLINGS against their
gender, and thus make complete fools and laughingstocks of
themselves in public. Bigotry is an EQUAL-opportunity mental
defect, when it comes to gender.

> Interesting, coming from someone who claims to respect women.

I have ZERO respect for bigots. I respect ALL men and women who
are sensible and intelligent enough to be FAIR-minded *egalitarians.*

BIGOTS **deserve** all the disrespect that they get from society.