[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Stopping a thread

Bill Atkins

2/7/2005 3:39:00 AM

Say I have a thread in variable @thread. Is it possible to stop that
thread from the main thread? I am aware of Thread.stop, but I don't
want to stop the current thread, just the thread represented in
@thread.

--
$stdout.sync = true
"Just another Ruby hacker.".each_byte do |b|
('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr
end; print "\n"


2 Answers

Assaph Mehr

2/7/2005 3:48:00 AM

0


Bill Atkins wrote:
> Say I have a thread in variable @thread. Is it possible to stop that
> thread from the main thread? I am aware of Thread.stop, but I don't
> want to stop the current thread, just the thread represented in
> @thread.

Look at Thread#kill. e.g.:

@thread = Thread.new {
while true
puts 'still going'
sleep 2
end
}

sleep 7
@thread.kill
puts 'done'

Bill Atkins

2/7/2005 3:53:00 AM

0

Brilliant! Thanks!

On Mon, 7 Feb 2005 12:50:09 +0900, Assaph Mehr <assaph@gmail.com> wrote:
>
> Bill Atkins wrote:
> > Say I have a thread in variable @thread. Is it possible to stop that
> > thread from the main thread? I am aware of Thread.stop, but I don't
> > want to stop the current thread, just the thread represented in
> > @thread.
>
> Look at Thread#kill. e.g.:
>
> @thread = Thread.new {
> while true
> puts 'still going'
> sleep 2
> end
> }
>
> sleep 7
> @thread.kill
> puts 'done'
>
>


--
$stdout.sync = true
"Just another Ruby hacker.".each_byte do |b|
('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr
end; print "\n"