Subject: Re: popen reentrant (was Re: SA/pthread and vfork)
To: Greywolf <greywolf@starwolf.com>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 09/11/2003 09:58:42
On Thu, 11 Sep 2003, Greywolf wrote:
> Funny, I was asking myself that same question yesterday.
>
> The thing I think we need to look at is that, realistically, threading
> is a superset of what a vfork() accomplishes, at least at my first glance.
>
> I have a question (okay, two):
>
> If a process threads itself into, say, four threads, can a thread
> fork()/exec() without destroying the parent?
Yes, a thread can fork()/exec() w/o destroying the parent. Just exec()ing
though kills the parent.
> Can a thread create another thread?
>
> Unless I'm mistaken, vfork() came into being because threading didn't
> exist at the time. Had threading been around, I doubt vfork() would ever
> have been written.
My understanding is different. It came about as it's expensive to copy a
whole process over if you know you're going to very soon tear all that
copy down with an exec(). So why not just stall the parent for a little
and borrow its address space? When you exec, just build a brand new
address space. Saves a vm space copy, which can be expensive.
Take care,
Bill