Andy Sy wrote:

From http://www.itworld.com/nl/lnx_tip/02092001/

"Under Linux, threads and processes are almost indistinguishable
except for one thing: threads run within the same address space
whereas processes have distinct address spaces. However, no
differences exist between the two from a scheduler point-of-view.
Thus, a context switch between two threads of the same process
essentially jumps from one code location to another, plus setting
a few CPU registers."

Whoops, the last sentence was a non sequitur, I need to include the other parts of the article:

"What happens when you launch a new process? Linux implements
the copy-on-write model, which leaves the mapped memory shared
between a parent process and its child as long as the child doesn't
alter the shared addressable region. Only when the child writes to
the shared address space does the kernel allocate new storage.
Hence, launching a new process in Linux involves significantly
lower overhead compared to Solaris and other OSs."

and the very notable conclusion:

"In fact, many multithreaded applications ported from other platforms
to Linux can benefit from *** replacing multithreading with
multiprocessing ***; this will eliminate the overhead of critical
sections and other locking mechanisms used in multithreaded
applications."


Apparently, copy-on-write is such a useful feature that other Unices have evolved a vfork() call for such a purpose. In Linux, that is already the default behaviour of fork() and you are saved from having to make a choice, although you would probably want to use vfork() - just a wrapper for Linux's fork() - to maintain compatibility with other *nixes. OTOH, that would then break compatibility with *nixes which DON'T have vfork()! Sigh... I guess that's why the autocrap tools exist...

Anyway, this is certainly a useful fact to discover as there is a growing
sentiment that 'threads are evil' due to the fact that thread-related bugs
are often exceedingly hard to track.


-- ============================================= reply-to: a n d y @ n e o t i t a n s . c o m http://www.neotitans.com Web and Software Development -- Philippine Linux Users' Group (PLUG) Mailing List [EMAIL PROTECTED] (#PLUG @ irc.free.net.ph) Official Website: http://plug.linux.org.ph Searchable Archives: http://marc.free.net.ph . To leave, go to http://lists.q-linux.com/mailman/listinfo/plug . Are you a Linux newbie? To join the newbie list, go to http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie

Reply via email to