On Fri, Aug 10, 2012 at 2:47 PM, Bartosz DziewoĆski <[email protected]> wrote:
> 2012/8/10 ajay paswan <[email protected]>:
>> How can I ensure that the main child lives till all children finishes
>> their jobs and get killed?
>
> Thread#join?
You can remove the question mark. :-)
A typical idiom looks like this
threads = 10.times.map {|i| Thread.new { ... } }
...
threads.each &:join
# alternative: collect all results
results = threads.map &:value
>> Is there any way that I can invoke a function when a thread gets killed?
>
> I don't understand. Are you looking for #at_exit?
That is invoked when the main thread exits but not per thread. Per
thread one can do
Thread.new do
begin
do_work
ensure
printf "Thread dies %p\n", Thread.current
end
end
But using Thread#join or Thread#value is usually sufficient.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en