gcl-devel
[Top][All Lists]
Advanced

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

[Gcl-devel] FYI http://www.itworld.com/nl/lnx_tip/02092001/


From: Camm Maguire
Subject: [Gcl-devel] FYI http://www.itworld.com/nl/lnx_tip/02092001/
Date: 01 Nov 2005 21:08:13 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Of course all such come with a grain of salt...

I've found a few other posts reporting Linux process creation as 1.8
to 2.5 times slower than thread creation -- much less than the factor
of 10 I was expecting.

Take care,
=============================================================================
Processes and Threads
Sign up for LINUX TIPS AND TRICKS
More Newsletters
 Printer Friendly Format
 Mail to a friend

LINUX TIPS AND TRICKS --- 02/09/2001



Danny Kalev

This week, I will present the fundamentals of processes and threads in
Linux, compare them to other operating systems, and draw some
practical lessons.

Advertisement
On this topic
Newsletters
Linux Tips and Tricks. Sign up Now!
More news on this subject
Red Hat, HP ship Linux Itanium 2 workstations

UnitedLinux plans under-$1,000 release, US entity

Linux takes confidence says RS/6000 supporter

Gartner: Linux will be the savior of Unix

HP to work with US government on Linux clusters
White Papers
Unix
Search the Newsletter Archives
View the LINUX TIPS AND TRICKS Archive

In the Beginning

GUI-based systems? advent (around 10 years ago) provided the impetus
to switch from multiprocessing to multithreading. Classic operating
systems, e.g. Solaris, associated a process with a private table of
file descriptors, a unique PID, a table of signal handlers, and a
private address space. Obviously, launching a new process (e.g., by
calling fork() or a similar function) required considerable
overhead. The child process would get its own copy of the parent's
addressable region, table of file descriptors, and so on. From this
limitation arose threads.

Unlike processes, threads run within the same address space and share
their process' data. In such environments, the thread creation and
destruction takes place considerably faster compared to a full-blown
process' creation or destruction. Under Solaris, for example,
launching a new thread is about 70 times faster than launching a new
process. Linux, however, is radically different.

The Linux Approach

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.

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.

Some Unix systems support the vfork() function to implement copy-on-
write, as opposed to plain fork(), which copies the entire parent's
address space to a new region. However, under Linux fork()uses
copy-on- write anyway minimalizing the difference between the two
functions. In fact, vfork() merely serves as a wrapper function that
calls fork().

Practical Lessons

In this regard, Linux newcomers often are unaware of the substantial
differences between Linux and other operating systems. To implement
concurrency, they use multithreading exclusively, mistakenly assuming
as high an overhead associated with Linux multiprocessing as on other
platforms. However, this is not the case. 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.

 
Danny Kalev is a system analyst and software engineer with more than
10 years of experience, specializing in C++ and object-oriented
analysis and design on various platforms including VMS, DOS, Windows,
Unix, and Linux. His technical interests involve code optimization,
networking, and distributed computing. He is also a member of the ANSI
C++ standardization committee and the author of ANSI/ISO C++
Professional Programmer's Handbook (Que, 1999). Danny can be reached
at address@hidden
=============================================================================

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]