Re: fork ???



Magnus Wirström <asd@mail.bip.net> writes:
> I have looked into threads and it seems easy to do and seems
> portable, Is fork() better in some way or is it a good idea to use
> threads ? Hmmm ... anyone that knows benefits of fork() or threads ?
> If I create a thread does it let my app to continue it's main ? or
> is it waiting on it to finnish ... If I understand threads right it
> should start a process that lives for itself until it exits, Am I
> missing the point or did I understand threads correctly ?
> 

Fork copies the address space of the process (all your data
structures), threads do not. So threads share the data. This means
threads are much more complicated to use, but avoid copying so much
data.

(Though on any reasonable UNIX the copy done by fork() is
copy-on-write, so it isn't all that slow typically.)

Use fork() if you're going to exec(). Use threads if fork() won't
work.

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]