> If both pthread_create and fork are wrappers over the clone system call
> is there any advantage of using threads over processes
There is. When you fork whole of the process data area is
duplicated (even if its marked copy or write, it eventually would have to
be duplicated to some extent, in case of a threaded app), that doesn't
happen with threads. Just having a single kernel extry point (clone)
doesn't mean the behavior is same.
AFAIK, when you just clone (create a thread), a new entry is made
in the process table, such that the lower 16 bits of the pid are same as
parent, and the upper 16 bits represent the thread number. And both
"processes" share the same code/data areas.
In essence threads are still lighter on the system, although the
time taken for pthread_create/clone is almost identical on linux.
BTW does anyone know what happens to stack? IIRC, linux uses the
bottom of data area as stack? Does it get duplicated, and properly mapped
so that each thread sees its own stack??
Regards,
Kedar.
-----------------------------------------------------------------------
For more information on the LIH mailing list see:
http://lists.linux-india.org/lists/LIH