On Fri, Aug 10, 2012 at 2:47 PM, Bartosz Dziewoski <matma.rex / gmail.com> wrote:
> 2012/8/10 ajay paswan <lists / ruby-forum.com>:
>> 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/