[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Threading from a loop

Nicholas Poole

11/12/2007 12:53:00 PM

Hi,

My problem is that I want a function to start as a new thread every time
it's called, hence allowing the loop to continue and spawn a thread for
each iteration of the loop. Currently my loop waits for the function to
end before it continues. If anyone can anyone tell me what I'm missing,
or even refer me to some good documentation, I'd be grateful.

My current code is as follows:

cl.add_message_callback do |m|
if m.type != :error
#break off
newreplythread = Thread.new(cl, m) {
#function call is here
}
end
}

(Maybe I'm mistaking the loop for something else, but it's behaviour
apears the same)


Thanks

NickPoole
--
Posted via http://www.ruby-....

6 Answers

Roger Pack

11/12/2007 7:23:00 PM

0


> My current code is as follows:
>
> cl.add_message_callback do |m|
> if m.type != :error
> #break off
> newreplythread = Thread.new(cl, m) {
> #function call is here
> }
> end
> }
>
> (Maybe I'm mistaking the loop for something else, but it's behaviour
> apears the same)
>
>
> Thanks
>
> NickPoole


Code looks good to me unless its never being called.
http://www.rubycentral.com/pickaxe/tut_th...
--
Posted via http://www.ruby-....

7stud --

11/12/2007 10:12:00 PM

0

Nicholas Poole wrote:
> Hi,
>
> My problem is that I want a function to start as a new thread every time
> it's called, hence allowing the loop to continue and spawn a thread for
> each iteration of the loop. Currently my loop waits for the function to
> end before it continues. If anyone can anyone tell me what I'm missing,
> or even refer me to some good documentation, I'd be grateful.
>
> My current code is as follows:
>
> cl.add_message_callback do |m|
> if m.type != :error
> #break off
> newreplythread = Thread.new(cl, m) {
> #function call is here
> }
> end
> }
>
> (Maybe I'm mistaking the loop for something else, but it's behaviour
> apears the same)
>

Try this:

def greet
puts 'hello'
end


threads = []

5.times do |i|
threads << Thread.new do
sleep(rand() * 10)
puts "thread#{i}"
greet
puts
end
puts "loop#{i}"
end
puts

threads.each{|thr| thr.join}

--output:--
loop0
loop1
loop2
loop3
loop4 #Note that all loop iterations are completed

thread3
hello

thread0
hello

thread4
hello

thread1
hello

thread2
hello
--
Posted via http://www.ruby-....

Adam H. Kerman

10/29/2013 6:49:00 PM

0

anim8rFSK <anim8rfsk@cox.net> wrote:
>JRStern <JRStern@foobar.invalid> wrote:
>>On Mon, 28 Oct 2013 22:15:34 -0700, anim8rFSK <anim8rfsk@cox.net> wrote:

>>>Rick needs to kick Alexis to the curb. Stupid little bitch. Let me
>>>know if bee counter dies; hopefully he'll take Alexis with him.

>>Next week teaser says he's on death row.

>>We can only hope.

>Was that him? I heard "Alexis' friend" but I didn't dare dream it was
>him. Not that it matters, it takes decades for them to fry you.

>They played this completely wrong. I mean, the guy is objectively
>worthless. And yet nobody but Castle sees it. Alexis clearly picked
>the most useless person she could find for the express purpose of
>punishing her father ... for getting engaged to Beckett!?!? The other
>women in his life saying "it's her choice" have a point, but it needs to
>be accompanied by "yes, he's possibly the biggest waste of protoplasm
>imaginable, a complete parasitical dung bag" and somebody needs to
>mention that Alexis isn't the smart one any more. Castle can't suffer
>this fool, and he can't tell Beckett why Alexis is doing this without
>tearing him and Beckett apart, but he can't NOT tell Beckett either, and
>pretty much the same goes for Grandma. Alexis used the last of her
>smarts to destroy her father's life, and with them gone, didn't notice
>she pretty much ruined her own in the process. I've forgotten who
>Alexis' mother is ... where is she in all this?

Yeah, I agree with fred. Gawd, what a stupid and hurtful thing for Alexis
to say to her father, that she resented him for the way she found out about
the engagement. Yeah, Castle's mother has a big mouth; it sure as hell
WASN'T her news to tell, but so what? Wasn't Alexis of the opinion that her
father should have proposed to Beckett four years earlier?

jt

10/29/2013 7:22:00 PM

0

On Tue, 29 Oct 2013 18:49:06 +0000 (UTC), "Adam H. Kerman" <ahk@chinet.com>
wrote:

>anim8rFSK <anim8rfsk@cox.net> wrote:
>>JRStern <JRStern@foobar.invalid> wrote:
>>>On Mon, 28 Oct 2013 22:15:34 -0700, anim8rFSK <anim8rfsk@cox.net> wrote:
>
>>>>Rick needs to kick Alexis to the curb. Stupid little bitch. Let me
>>>>know if bee counter dies; hopefully he'll take Alexis with him.
>
>>>Next week teaser says he's on death row.
>
>>>We can only hope.
>
>>Was that him? I heard "Alexis' friend" but I didn't dare dream it was
>>him. Not that it matters, it takes decades for them to fry you.
>
>>They played this completely wrong. I mean, the guy is objectively
>>worthless. And yet nobody but Castle sees it. Alexis clearly picked
>>the most useless person she could find for the express purpose of
>>punishing her father ... for getting engaged to Beckett!?!? The other
>>women in his life saying "it's her choice" have a point, but it needs to
>>be accompanied by "yes, he's possibly the biggest waste of protoplasm
>>imaginable, a complete parasitical dung bag" and somebody needs to
>>mention that Alexis isn't the smart one any more. Castle can't suffer
>>this fool, and he can't tell Beckett why Alexis is doing this without
>>tearing him and Beckett apart, but he can't NOT tell Beckett either, and
>>pretty much the same goes for Grandma. Alexis used the last of her
>>smarts to destroy her father's life, and with them gone, didn't notice
>>she pretty much ruined her own in the process. I've forgotten who
>>Alexis' mother is ... where is she in all this?
>
>Yeah, I agree with fred. Gawd, what a stupid and hurtful thing for Alexis
>to say to her father, that she resented him for the way she found out about
>the engagement. Yeah, Castle's mother has a big mouth; it sure as hell
>WASN'T her news to tell, but so what? Wasn't Alexis of the opinion that her
>father should have proposed to Beckett four years earlier?

I can't imagine anyone watches this show for that soap opera. It never even
occurred to me to quit watching based on about 1 minute of dialog with his
daughter. Sure Alexis was an ungrateful little bitch but who cares? I
watch Castle for Filion and the cases.

The last two episodes were light, tongue-in-cheek, episodes. Perfect
examples of what Castle does best. The "time travel" episode especially.
"Best case ever".

When they try doing serious episodes like Becket at the FBI, Becket trying
to uncover who's responsible for her mom's murder for the umpteenth time or
Castle trying to play Liam Neeson in Taken it's just stupid. It also bores
the hell out of me. Though I do admit that the latter was at least funny
when Espo made a comment about him not being Liam Neeson.

Anim8rFSK

10/29/2013 8:07:00 PM

0

In article <sv1079lrkaspo7qe5m28oru7qgd9rk4a8p@4ax.com>,
EGK <me@privacy.net> wrote:

> On Tue, 29 Oct 2013 18:49:06 +0000 (UTC), "Adam H. Kerman" <ahk@chinet.com>
> wrote:
>
> >anim8rFSK <anim8rfsk@cox.net> wrote:
> >>JRStern <JRStern@foobar.invalid> wrote:
> >>>On Mon, 28 Oct 2013 22:15:34 -0700, anim8rFSK <anim8rfsk@cox.net> wrote:
> >
> >>>>Rick needs to kick Alexis to the curb. Stupid little bitch. Let me
> >>>>know if bee counter dies; hopefully he'll take Alexis with him.
> >
> >>>Next week teaser says he's on death row.
> >
> >>>We can only hope.
> >
> >>Was that him? I heard "Alexis' friend" but I didn't dare dream it was
> >>him. Not that it matters, it takes decades for them to fry you.
> >
> >>They played this completely wrong. I mean, the guy is objectively
> >>worthless. And yet nobody but Castle sees it. Alexis clearly picked
> >>the most useless person she could find for the express purpose of
> >>punishing her father ... for getting engaged to Beckett!?!? The other
> >>women in his life saying "it's her choice" have a point, but it needs to
> >>be accompanied by "yes, he's possibly the biggest waste of protoplasm
> >>imaginable, a complete parasitical dung bag" and somebody needs to
> >>mention that Alexis isn't the smart one any more. Castle can't suffer
> >>this fool, and he can't tell Beckett why Alexis is doing this without
> >>tearing him and Beckett apart, but he can't NOT tell Beckett either, and
> >>pretty much the same goes for Grandma. Alexis used the last of her
> >>smarts to destroy her father's life, and with them gone, didn't notice
> >>she pretty much ruined her own in the process. I've forgotten who
> >>Alexis' mother is ... where is she in all this?
> >
> >Yeah, I agree with fred. Gawd, what a stupid and hurtful thing for Alexis
> >to say to her father, that she resented him for the way she found out about
> >the engagement. Yeah, Castle's mother has a big mouth; it sure as hell
> >WASN'T her news to tell, but so what? Wasn't Alexis of the opinion that her
> >father should have proposed to Beckett four years earlier?

And she was off in South America at the time! It's not like she was
still living at home, or even in the dorms, where she could reasonably
except Dad to talk to her.

--
Wait - are you saying that ClodReamer was wrong, or lying?

erilar

10/29/2013 10:03:00 PM

0

In article <l4ovv2$frq$3@news.albasani.net>,
"Adam H. Kerman" <ahk@chinet.com> wrote:

> Yeah, I agree with fred. Gawd, what a stupid and hurtful thing for Alexis
> to say to her father, that she resented him for the way she found out about
> the engagement. Yeah, Castle's mother has a big mouth; it sure as hell
> WASN'T her news to tell, but so what? Wasn't Alexis of the opinion that her
> father should have proposed to Beckett four years earlier?

They have rewritten this character disastrously. The girl we knew from
earlier years on the show would never have treated her father this way.

--
Erilar, biblioholic medievalist