Is tonight UNIX night? :-)

On Wed, Mar 26, 2008 at 6:09 PM, Joey Marino <joey.da3rd / gmail.com> wrote:

>  db = MySQL.new
>
>  fork do
>   obj1 = Object1.new(db)
>   obj1.addToDb
>  end
>  Process.wait
>
>  fork do
>   obj2 = Object2.new(db)   #Object1 and Object2 are inherited from the same
>  superclass
>   ob2.addToDb   #db error occurs here
>  end
>  Process.wait

 When you fork you create a new process.  When you reach the "end" of
 the block, that process exits.  My guess is that when your code passes
 the first Process.wait, your MySQL object was torn down by the dieing
 process.

 Look at this code:

#!/usr/bin/env ruby

END { puts "Bye from #{Process.pid}" }

fork do
    puts "Hello from #{Process.pid}"
end

Process.wait

fork do
    puts "Hello from #{Process.pid}"
end

Process.wait

 What do you expect to see when you run it?

 Marcelo