Stopping a thread

B

Bill Atkins

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.
 
A

Assaph Mehr

Bill said:
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'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,448
Latest member
DeanaQ4445

Latest Threads

Top