Tanaka Akira <akr / fsij.org> wrote:
> 2013/12/7 Eric Wong <normalperson / yhbt.net>:
> > However, I want to do this via callback, example with Worker class:
> >
> >     class Worker
> >       attr_writer :pid
> >
> >       def initialize
> >         @r, @w = IO.pipe
> >         Process.atfork_parent { @r.close unless @r.closed? }
> >         Process.atfork_child { @w.close unless @w.closed? }
> >       end
> >     end
> >
> >     worker = Worker.new # IO.pipe
> >     worker.pid = fork { ... }
> >     ...
> >
> >     # No need to remember what to close in parent/child
> 
> I think it doesn't work with multiple thread.

True, but I wasn't intending this example to be used for an MT
application, but a single-threaded, multi-process HTTP server.

Generally, I do not use fork after I've spawned threads (unless
followed immediately with exec).