Why Linux, Programming and more threads with the process less

sponsored links
Linux kernel under-Linux thread program to achieve more with the process less why the thread of the second

1, Linux kernel and multi-threaded multi-process support approach
Linux thread implementation is outside of the nuclear, nuclear is the creating process to provide the interface do_fork (). Kernel provides two system calls __clone () and fork (), eventually called with different parameters do_fork () nuclear API. do_fork () provides a lot of parameters, including CLONE_VM (shared memory space), CLONE_FS (shared file system information), CLONE_FILES (shared file descriptor table), CLONE_SIGHAND (shared signal handler table) and CLONE_PID (sharing the process ID, only nuclear process, that is, the process of effective No. 0).
When using the fork system call produces more than process, the kernel calls do_fork () does not use any shared property, the process has independent operating environment.
When using the pthread_create () to create a thread, then the final set all of these properties to call __clone (), then all of these parameters passed to the nucleus of do_fork (), to create a "process" has a shared operating environment, only the stack is independent, __clone () introduced.
That is: Linux, whether under the multi-threaded programming or multi-process programming, the ultimate realization of multi-process with do_fork programming, but the process of creation of the parameters are different, leading to a different shared environment.
Linux threads are lightweight processes in the nucleus exists in the form of, an independent process entry, and all creation, synchronization, and delete operations are conducted outside the core of pthread library. pthread library to use a managed thread (__pthread_manager (), each process independently and only) to manage thread creation and termination, the thread assigned thread ID, sending a signal related thread, but the main thread pthread_create ()) while the caller request information through the pipeline to pass management of threads.

/************ On this document ********************************** **********
* Filename: Linux kernel under-Linux thread program to achieve more with the process less why the thread of the two
* Purpose: of Linux, multi-threaded multi-process and the relationship between
* Wrote by: zhoulifa ( zhoulifa@163.com ) Zhou Lifa ( http://zhoulifa.bokee.com )
Linux Linux enthusiasts disseminator of knowledge SOHO, developers are best at C programming language
* Date time :2006-07-12 21:20:00
* Note: Any person may copy the code and any use of these documents, including of course your commercial use
* But please follow the GPL
* Hope: More and more people wish to contribute their efforts, contribute to the development of science and technology
************************************************** *******************/

Second, Linux lightweight process under a lot of friends say that the benefits of using multiple threads is less resource consumption, the implied meaning that is resource-intensive process more than the thread, right?
But in fact, under Linux it really points more than the process with a lot of resources? Leaving aside the process is more resource-intensive than the thread, the number of resources on the process, the case of occupation, Linux is really doing quite a savings. Produce more than one process, certainly point to produce the memory is to replicate the process table entry, that is, a task_struct structure, but the structure itself has done quite compact. Other terms for a process to some data segment, code segment, stack segment is not completely copy it? For multi-process, the code is certainly not copied, because the parent process and child process is the same code segment, data segment and stack segment it? Not necessarily, because in Linux, a widely used technique called copy-on-write, that when writing copy. copy-on-write mean? Means that resources have been saved, assuming a variable x in the parent process in existence, when the parent process creates a child process or sub process, the variable x is copied to the child process memory space? No, the child process and the parent process use the same memory space, variable, or a parent when the child process to change the value of the variable x will be copied to the variable, leading to his son the value of different variables in the process of.
The following code shows a father and son during this testing process variables can not be shared:
# Include <sys/types.h>
# Include <unistd.h>
# Include <stdio.h>
# Include <unistd.h>
# Include <stdio.h>
# Include <errno.h>

# Define PARENTSLEEP 5
# Define INTERVALSLEEP 3
int main (int argc, char ** argv)
(
int x = 0;
pid_t chldpid;
x = 5;
chldpid = fork ();
if (chldpid <0) (
perror ("fork");
return 0;
)
else if (chldpid> 0) (
printf ("here is the parent process \ n");
printf ("variable x (in parent) is:% d \ n", x);
x = 8;
sleep (PARENTSLEEP);
printf ("again variable x (in parent) is:% d \ n", x);
sleep (INTERVALSLEEP);
printf ("last variable x (in parent) is:% d \ n", x);
waitpid (0, NULL, 0);
)
else (
printf ("\ there is the child process \ n");
printf ("\ tvariable x (in child) is:% d \ n", x);
sleep (INTERVALSLEEP);
printf ("\ tagain variable x (in child) is:% d \ n", x);
sleep (INTERVALSLEEP);
x = 10;
sleep (INTERVALSLEEP);
printf ("\ tlast variable x (in child) is:% d \ n", x);
)
return 0;
)

The operation results are as follows:
/ *
here is the child process
variable x (in child) is: 5
here is the parent process
variable x (in parent) is: 5
again variable x (in child) is: 5
again variable x (in parent) is: 8
last variable x (in parent) is: 8
last variable x (in child) is: 10
* /

Can be seen from the above code, the process variables are independently of each other's son. Unfortunately the process address space as father and son are completely separated, the address of the variable can be exactly the same, so I can not use the code to verify that the variable is indeed different variables, there are some who think of verification code?

Third, a good article, it read the article below, because I think I can not write more words here, the article source is http://ww-128.ibm.com/developerworks/cn/linux/kernel / l-thread /
/************** Reference start **************/

Linux thread implementation mechanism



Levels:

Yang Sha Chau School of Computer Science University of Defense Technology

May 19, 2003

Since the concept of multi-threaded programming in Linux, since, Linux application development is always multi-line and the two issues are inescapable stakeholders: compatibility, efficiency. From the start threading model, by analyzing the most popular Linux platform LinuxThreads thread library implementation and inadequate description of the Linux community is how to treat and resolve the compatibility and efficiency of these two issues.

1. Basics: Threads and processes

In accordance with the textbook definition, the process is the smallest unit of resource management, the thread is the smallest unit of program execution. Operating system design, evolved from the process thread, the main purpose is to better support SMP, and reduce (process / thread) context switching overhead.

No matter what kind of points system according to a process of at least one instruction execution thread as its body, the process of managing resources (such as cpu, memory, file, etc.), but the thread assigned to execute a cpu. Of course, a process can have multiple threads, at this time, if the process running on SMP machines, it can use multiple cpu to perform all threads, to the greatest degree of parallelism to improve efficiency; the same time, even in single-cpu machines, multi-threading model to the design process, as the current multi-process model instead of single process models, make the design more compact, more complete implementation of the procedures more efficient, such as using multiple threads to respond to multiple input at a time when multi-threaded model to achieve the functions of fact can also be used to achieve multi-process model, with the latter, the thread context switching overhead much smaller than the process, from the semantic point of view, while responding more inputs such functions, in fact shared all the resources than the other cpu.

Two major significance for the threading model, respectively, developed a core-level threads and user-level thread two thread model, classification criteria are thread scheduling in the nucleus or nuclear outside. The former is more conducive to concurrent use of multiple processor resources, while the latter is a more considered context switch overhead. In the current commercial systems in the two normally used together, both Tigonghexin thread Yi meet smp system needs, also Zhi Chi Fang Shi with thread library in user state mechanism to achieve another set of threads, a core thread Tongshi Cishi a state of thread scheduling multiple users who. Like many technologies, "mixed" can usually result in higher efficiency, but also to achieve greater difficulty, for "simple" design concept, Linux did not realize from the outset, mixed model plan But it adopted in the realization of another idea of "mixed."

Concrete realization of the thread mechanism, you can achieve in the operating system kernel threads can also be achieved in nuclear outside, which obviously requires at least achieved the nuclear process, while the former is generally required in the nucleus also supports the process. Core-level thread model obviously requires the support of the former, while the user-level thread model is not necessarily based on the latter to achieve. Such differences are noted earlier, are two different classification standards bring.

Both support the process when the nucleus also supports threads, the thread can be achieved - the process of "many to many" model, that is, a process scheduling a thread from the nucleus, while it can also be as user-level scheduling by the thread pool , select the appropriate user-level thread to run in its space. This is the previously mentioned "hybrid" threading model, can meet the needs of multi-processor system can also reduce the maximum scheduling overhead. Most commercial operating systems (such as Digital Unix, Solaris, Irix) are used to the full realization of this threading model POSIX1003.1c standards. Achieved in nuclear outer thread can be divided into "one to one", "many to one," the two models, the former with a core process (perhaps a lightweight process) corresponds to a thread, the thread scheduling is equivalent to the process of scheduling, pay to the core to complete, which is entirely in multi-core threading, scheduling is also user mode to complete. The latter is the previously mentioned simple model of user-level thread implementations, it is clear that the nuclear outer thread scheduler thread running in fact only need to complete the switch stack, scheduling overhead is very small, but because the core of the signal (whether is synchronous or asynchronous) are in the process as a unit, and therefore can not locate the thread, so that implementations can not be used for multiple-processor systems and this demand is becoming increasingly large, therefore, in reality pure user-level thread implementation, in addition to algorithms other than research purposes, has almost disappeared.

Linux kernel only provides lightweight support for the process, limits the threading model more efficient implementation, but the Linux focus on optimizing the process of scheduling overhead, to some extent makes up for this shortcoming. The most popular thread mechanism is used LinuxThreads thread - the process of "one on one" model, scheduling to the core, and in a user-level implementation, including signal processing, including thread management. Linux-LinuxThreads operating mechanism is the focus of this article describes.







2. Linux 2.4 kernel to achieve light weight process

The initial process definition contains procedures, resources and implementation of three parts, which usually means the program code, resources, usually in the operating system level resources, including memory, IO resources, signal processing part and the implementation of the procedures for the implementation of the context is usually understood, including the cpu occupation, and later developed into a thread. Concept appears in the thread before the switching process to reduce overhead, operating system designers have gradually revised the concept of the process, and gradually allow the process of share some resources, a spin-off from the main body to allow some part of the process of sharing resources such as files, signals , data memory, and even the code, which developed the concept of lightweight processes. Linux kernel version 2.0.x has achieved a light on the process, the application can be a single clone () system call interface, with different parameter specifies the process to create lightweight or normal process. In the kernel, clone () call to pass through the parameters and interpretation will call do_fork (), the nuclear function is also a fork (), vfork () system call for the eventual realization of:


int do_fork(unsigned long clone_flags, unsigned long stack_start, 
struct pt_regs *regs, unsigned long stack_size)
which clone_flags from the following macro "or" value:

#define CSIGNAL                 0x000000ff      /* signal mask to be sent at exit */
#define CLONE_VM                0x00000100      /* set if VM shared between processes */
#define CLONE_FS        0x00000200      /* set if fs info shared between processes */
#define CLONE_FILES     0x00000400      /* set if open files shared between processes */
#define CLONE_SIGHAND   0x00000800      /* set if signal handlers and blocked signals shared */
#define CLONE_PID               0x00001000      /* set if pid shared */
#define CLONE_PTRACE    0x00002000      /* set if we want to let tracing continue on the child too */
#define CLONE_VFORK     0x00004000      /* set if the parent wants the child to wake it up on mm_release */
#define CLONE_PARENT    0x00008000      /* set if we want to have the same parent as the cloner */
#define CLONE_THREAD    0x00010000      /* Same thread group? */
#define CLONE_NEWNS     0x00020000      /* New namespace group? */
#define CLONE_SIGNAL        (CLONE_SIGHAND | CLONE_THREAD)




In do_fork (), different clone_flags will lead to different behaviors, for LinuxThreads, it uses (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND) parameter to call the clone () to create "threads", said shared memory, shared file system access count, shared file descriptor table, and shared signal processing. In this section, for these parameters, see Linux kernel is how to achieve these shared resources.

1.CLONE_VM

do_fork () need to call copy_mm () to set the task_struct in mm and active_mm items, the two mm_struct data associated with the process memory space corresponds to. If do_fork () when the specified CLONE_VM switch, copy_mm () will the new task_struct in mm and active_mm set the same with the current, while increasing the number of users of the mm_struct (mm_struct:: mm_users). In other words, lightweight process and the parent shared memory address space, can be seen from the next map to indicate the position in the process mm_struct:

Why Linux, Programming and more threads with the process less
2.CLONE_FS

task_struct in the use of fs (struct fs_struct *) where the file system records the process, the root and current directory information, do_fork () called when copy_fs () copy of this structure; and lightweight process is only increased for fs-> count count , and the parent process share the same fs_struct. In other words, lightweight process is not independent file system related information, the process of any one thread to change the current directory, root directory and other information that will directly affect other threads.

3.CLONE_FILES

A process may open some files in the process structure task_struct using files (struct files_struct *) to hold the process to open the file structure (struct file) information, do_fork () call the copy_files () to handle the process attribute; light level process is shared with the parent process of the structure, copy_files () when only increased fils-> count count. The sharing process allows any thread can access open files maintained by, the operation of their process will be directly reflected in the other thread.

4.CLONE_SIGHAND

Each Linux process can define their own approach to the signal, in the task_struct of the sig (struct signal_struct) use a struct k_sigaction structure array to store the configuration information, do_fork () in copy_sighand () is responsible for copying the information; lightweight process is not to copy, but simply increase the signal_struct:: count count, and share the structure of the parent process. In other words, the child process with parent process exactly the same signal processing method, and can change each other.

do_fork () in the work of many, this is not described in detail. For SMP systems, all processes fork out, have been assigned to the parent process with the same cpu, until the process is carried out only when the cpu scheduling options.

Although Linux support for lightweight processes, but it can not be said to support the core thread, because Linux "threads" and "process" in fact, in a dispatch level, share a process identifier space, this restriction makes the impossible Linux to achieve full sense of the POSIX thread mechanism, so many of the Linux thread library can only be as much as possible try to achieve most POSIX semantics, and as far as possible in function approximation.

3. LinuxThread thread mechanism

LinuxThreads is currently the most widely used Linux platform thread library, from Xavier Leroy (Xavier.Leroy @ inria.fr) responsible for the development and have been bound in GLIBC be issued. Its implementation is based on the core of lightweight process "one to one" thread model, a lightweight thread entity corresponds to a core process, and thread management between the external function library in achieving nuclear.

1. Thread describe the data structure and implementation of restrictions

Struct _pthread_descr_struct LinuxThreads defines a data structure to describe the thread, and use the global array variable __pthread_handles to describe and reference process under the jurisdiction of the thread. In __pthread_handles the first two, LinuxThreads global system defines two threads: __pthread_initial_thread and __pthread_manager_thread, characterized __pthread_manager_thread with __pthread_main_thread parent thread (the initial for the __pthread_initial_thread).

struct _pthread_descr_struct list is a double loop structure, __pthread_manager_thread where the list includes only one element of it, in fact, __pthread_manager_thread is a special thread, LinuxThreads uses only one of the errno, p_pid, p_priority the three domains. The __pthread_main_thread where the chain will process all user threads strings together. After a series of pthread_create () after the formation of __pthread_handles array will look like this:

Why Linux, Programming and more threads with the process less
newly created thread will occupy the first __pthread_handles an array, then the chain data structure with pointers to __pthread_main_thread headed into the linked list pointers. Use this list to create threads in the introduction and release time will be mentioned.

LinuxThreads follows the POSIX1003.1c standards, which on the thread library implementations of some limit, such as the process of the maximum number of threads, thread-private data area size, etc.. In the LinuxThreads implementation, follow these basic restrictions, but also made some changes, changes in the trend is to relax or expand these restrictions to make programming more convenient. These limits macro focus on sysdeps / unix / sysv / linux / bits / local_lim.h (different platforms use different file location), including the following points:

Private data of each process, key number, POSIX defines _POSIX_THREAD_KEYS_MAX as 128, LinuxThreads uses PTHREAD_KEYS_MAX, 1024; private data allowed to perform an action when the release number, LinuxThreads consistency with POSIX defined PTHREAD_DESTRUCTOR_ITERATIONS 4; each process the number of threads, POSIX is defined as 64, LinuxThreads increased to 1024 (PTHREAD_THREADS_MAX); thread running the minimum stack space, POSIX is not specified, LinuxThreads uses PTHREAD_STACK_MIN, 16384 (bytes).

2. Management thread

"One to One" One of the benefits model is completed by the kernel thread scheduling, while the other, such as thread cancellation, synchronization between threads, etc., are outside the thread library in the nuclear completed. In LinuxThreads, the specific structure for each process, a management thread to deal with thread-related management. When the process first call to pthread_create () creates a thread is created when (__clone ()) and start the manager thread.

In the space of a process, thread and other threads between management through a pair of "management channel (manager_pipe [2])" to communication, the pipeline management thread is created before the creation of threads in the successful launch of the management, the management pipeline Reading were assigned to write client-side and two global variables __pthread_manager_reader and __pthread_manager_request, after each user thread issued by __pthread_manager_request request to the management of threads, but the management of the thread itself does not directly use __pthread_manager_reader, pipe read end (manager_pipe [0]) as __clone () one of the parameters passed to manage threads, thread management is to monitor the work of the main pipe read end, and remove from the request to respond.

Create a management thread process is as follows:
(Global variable pthread_manager_request initial value of -1)

Why Linux, Programming and more threads with the process less
After initialization, the __pthread_manager_thread lightweight process number recorded in the allocation and management of nuclear outer thread id, 2 * PTHREAD_THREADS_MAX +1 This value will not conflict in any conventional user thread id. Management thread as pthread_create () the caller thread runs a sub-thread, and pthread_create () that created the user thread is a thread by the management to call the clone () to create, so the thread is actually a sub-thread management. (Where the concept of sub-thread should be understood as a child process.)

__pthread_manager () is the management of the thread where the main loop, after conducting a series of initialization into the while (1) loop. In the cycle, 2 seconds for the timeout thread to query (__poll ()) read-side management pipeline. In processing the request, check the parent thread (which is the main thread create a manager) has quit, quit to exit if the entire process. If the child thread needs to clear out, then call pthread_reap_children () clean up.

Then is read the pipeline's request, the request type implementation of the corresponding operation (switch-case). Specific request processing, source of the more clearly will not go into here.

3. Thread stack

In LinuxThreads, the management thread stack and user stack is a separate thread to manage the thread in the process heap via malloc () allocate a THREAD_MANAGER_STACK_SIZE byte stack area as their own run.

The user thread stack allocation with different architecture and different, mainly based on macro definitions to distinguish between the two, one is NEED_SEPARATE_REGISTER_STACK, this property is only used in IA64 platform; the other is FLOATING_STACK macro, in the few platforms to use i386 Deng , then the user thread stack is determined by the system and provide protection of the specific location. At the same time, users can also use the thread attribute structure to specify user-defined stack. Due to limited space, here only the use of two i386 platform stack organization: FLOATING_STACK mode and user-defined way.

In FLOATING_STACK mode, LinuxThreads use mmap () from kernel space allocated 8MB of space (i386 systems the default maximum stack size, if operating restrictions (rlimit), then in accordance with the operating limit settings), use the mprotect () to set the first of which a non-access area. The function of the space distribution of 8M as shown:

Why Linux, Programming and more threads with the process less
low addresses are used to monitor the protection of the page stack overflowed.

For user-specified stack, in accordance with the means for the industry, set the thread stack, and calculate the bottom of the stack, do not do protection and guarantee the correctness of the user.

Regardless of which organization, describe the structure of the thread is always in the top of the stack close to the location of the stack.

4. Thread id and process id

Each thread is both LinuxThreads thread id and process id, process id which is maintained by the kernel process ID, and thread id from LinuxThreads distribution and maintenance.

__pthread_initial_thread thread id for the PTHREAD_THREADS_MAX, __pthread_manager_thread is 2 * PTHREAD_THREADS_MAX +1, the first user thread's thread id is PTHREAD_THREADS_MAX +2, then the first thread in the thread n user id to follow the following formula:

tid=n*PTHREAD_THREADS_MAX+n+1


This distribution process ensures that all threads (including the already out) do not have the same thread id, and thread id of type pthread_t is defined as unsigned long integer (unsigned long int), also guarantees a reason running time will not repeat the thread id.

Id find the thread from the thread data structure is pthread_handle () function to complete, in fact thread number just by PTHREAD_THREADS_MAX modulus obtained is the thread in __pthread_handles in the index.

5. Thread creation

In pthread_create () to manage threads send REQ_CREATE request, management thread that calls pthread_handle_create () to create a new thread. Distribution of the stack, set the thread properties, to pthread_start_thread () entry for the function call __clone () to create and start a new thread. pthread_start_thread () to read their description of the process id number into the thread structure, and scheduling method according to which record allocation scheduling. Everything is ready, then call the real function of the thread execution, and after this function returns the call pthread_exit () clean up the scene.

6.LinuxThreads deficiency

As the Linux kernel constraints and the realization of the difficulty of reasons, LinuxThreads is not fully POSIX compliant, in its issue README has instructions.

1) The process id problem

This lack is the most critical shortage, caused because LinuxThreads involved a "one on one" model.

Linux kernel does not support true threads, LinuxThreads is using the same kernel with the ordinary process of scheduling view of the lightweight process to achieve thread support. These lightweight process, a process independent id, in the process of scheduling, signal processing, IO and so have the same capacity with the normal process. Appears in the source code reader is the Linux kernel clone () does not realize CLONE_PID parameter support.

In the kernel do_fork () in the treatment of the CLONE_PID like this:

if (clone_flags & CLONE_PID) {
                if (current->pid)
                        goto fork_out;
        }


This code shows that the current Linux kernel only in the pid of 0 recognized CLONE_PID parameters when, in fact, only in the SMP is initialized when the process will be created manually using CLONE_PID parameters.

In accordance with the POSIX definition, the same process should be shared for all threads of a process id and the parent process id, which in the current "one on one" model can not be achieved.

2) The signal processing problem

Since the kernel to process the asynchronous signal is distributed as a unit, while the LinuxThreads kernel for each thread is a process and not achieved the "thread group", and therefore do not meet certain semantic POSIX standard, such as the process not achieved send a signal to all threads, README which described.

If the core does not provide real-time signal, LinuxThreads uses SIGUSR1 and SIGUSR2 for internal use of the restart, and cancel the signal, so the application can not use both for the user to retain the original signal was. In later versions of Linux kernel 2.1.60 support expansion of real-time signal (from _SIGRTMIN to _SIGRTMAX), so there is no problem.

The default action of certain signals difficult to achieve in the current system, such as SIGSTOP and SIGCONT, LinuxThreads only a thread hang, but can not hang the whole process.

3) the total number of questions thread

LinuxThreads will be the maximum number of threads per process is defined as 1024, but in fact this value is also subject to the overall process of the system limit, which in turn is due to the core of the process thread.

In kernel 2.4.x, the use of a new calculation of the total number process, making the total process is basically only a limited number of physical memory size, the formula in the kernel / fork.c of fork_init () function:

max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) / 8



In the i386 on, THREAD_SIZE = 2 * PAGE_SIZE, PAGE_SIZE = 2 ^ 12 (4KB), mempages = physical memory size / PAGE_SIZE, 256M of memory for the machine, mempages = 256 * 2 ^ 20 / 2 ^ 12 = 256 * 2 ^ 8, then the maximum number of threads 4096.

But in order to ensure that every user (except root) processes more than half of the total number of occupied physical memory Buzhi Yu, fork_init () to continue to specify:

init_task.rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;

init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;

The number of these processes checks are do_fork () carried out, therefore, LinuxThreads, the total number of threads simultaneously by three factors.

4) Management issues thread

Management thread easily become a bottleneck, which is a common problem of this structure; the same time, the thread is also responsible for managing the clean-up the user thread, so, despite the management thread has blocked most of the signal, but once the management thread die, the user would have to thread hand-cleared, and the user does not know how to manage thread thread state, after the request thread creation, etc. No deal.

5) Synchronization

LinuxThreads thread synchronization in the signal is largely based on the establishment of this core complex by the synchronization signal processing system, efficiency has been a problem.

6) other POSIX compatibility problems

Many of Linux system calls, in accordance with the semantics are associated with the process, such as nice, setuid, setrlimit, etc., in the current LinuxThreads, these calls affect only the caller thread.

7) Real-time problem

The introduction of the thread has some real-time considerations, but temporarily does not support LinuxThreads, such as scheduling options, not yet realized. LinuxThreads only that, the standard Linux in real time on very little consideration.

4. Other threads to achieve system

LinuxThreads problem, especially compatibility issues, a serious impediment to the Linux on the cross-platform applications (such as Apache) uses multi-threaded design, which allows Linux applications on the thread has been maintained at relatively low levels. In the Linux community has a lot of people to work to improve thread performance, including both user-level thread library, but also the core-level and user-level thread library with improvements. Currently there are two most promising projects, one led by RedHat Inc. developed NPTL (Native Posix Thread Library), the other is IBM investing in the development of NGPT (Next Generation Posix Threading), both of which are fully compatible with POSIX 1003.1 around c, while in the nucleus and nuclear achieved outside to do work to-many threading model. Both models are to some extent make up for the shortcomings of LinuxThreads, are warming up again and a new design.

1.NPTL

NPTL summarize the design goals can be summarized as follows:

  • POSIX compatibility
  • The use of SMP structure
  • Low startup costs
  • Low link cost (ie, the procedure does not use the thread pool should not be affected by the thread)
  • LinuxThreads binary compatibility with applications
  • Hardware and software scalability
  • Multi-architecture support
  • NUMA support
  • And C + + integration

In the technology on, NPTL threading model is still 1:1, and with glibc and the latest development version of Linux Kernel2.5.x in signal processing, thread synchronization, memory management and other aspects were optimized. And different LinuxThreads, NPTL does not use and management of threads, the core thread of the management carried out directly on the nucleus, which also brings the performance optimization.

Mainly because the core of the problem, NPTL is still not 100% POSIX compatible, but the performance has been largely in terms of relative LinuxThreads the improved.

2.NGPT

IBM's open source project NGPT at January 10, 2003 launch of the stable 2.2.0 version, but even worse a lot of work related documents. As far as known, NGPT is based on GNU Pth (GNU Portable Threads) project to achieve the M: N model, and GNU Pth is a classic user-level thread library implementation.

In accordance with the March 2003 NGPT notice on the official website, NGPT NPTL increasingly widely considered acceptable, in order to avoid different threads library version confusion, and will not be further developed now to support the maintenance of sex. In other words, NGPT has given up competing with the next generation of Linux POSIX NPTL thread library standards.

3. Other high Thread

Here without mentioning Scheduler Activations. The ACM published in 1991 in multi-threaded core architecture affects the design of many multi-threaded cores, including Mach3.0, NetBSD and commercial versions of Digital Unix (now known as Compaq True64 Unix). Its essence is to use user-level thread scheduling in the same time, to minimize user-level request to the core of the system call, which is often an important source of operating expenses. Thread mechanism using this structure is actually a combination of flexible and efficient user-level threads and kernel-level thread of relevance, therefore, including Linux, FreeBSD, including several open source operating system design communities are conducting research, trying to achieve in this system Scheduler Activations.

/************** Reference end of the **************/
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Why Linux, Programming and more threads with the process less

  • Ruby Rails system calls the use of Ping

    Want to use call system commands under RoR, the general exec and system and the syscall Want to use in Rails, the call ping command The most common are ruby support Ping usage is as follows: Ping contains routines to test for the reachability of remote ho

  • The use of Ajax-bridge

    Administrative divisions in the choice of the function of the tree to use the ajax-bridge, Flex part can have a Tree Choose administrative divisions, after the completion of selection AJAX to refresh the page of data; AJAX pop-up page one and another ...

  • SUI-JavaScript rich UI library integration solution

    Introduction: SUI is not a class implementation of the UI, nor is it a standard set of UI markup language, it is just to help the existing UI frameworks (such as Ext, YUI like) to mark the way to the statement and the creation of UI. The names of these ta

  • jdbc even ORACLE, SQLServer2000, mysql ways

    According to other people say can make a ride to one of the clear step by step, not as easy to write your own ideas! 1. Even the oracle The direct use of the oracle are provided give a jar package jdbc: oracle alone is installed, and 10g of oracle on ...

  • Rails source code analysis (1): RailsFCGIHandler

    In accordance with the sequence starting from the beginning CGI Ruby CGI Doc: The Common Gateway Interface ( CGI ) Is a simple protocol for passing an HTTP request from a web server to a standalone program, and returning the output to the web browser ...

  • JUnit Unit Testing Summary

    Read some of the unit test article, from the article in the interception of a number of information, which could be considered in the learning process, a summary of it! See future! Unit testing code is not used to prove you are right, but in order to ...

  • Using Rails Captcha plug-in, easy implementation Verification Code

    Simple Captcha Plugin Can help us easily in the Rails implementation of Verification Code function. In addition, he has the option to provide sufficient to meet the U.S. requirements for certification, the use of easy. Supported picture and digital authen

  • Hibernate Inteceptor

    The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

  • Ruby on Rails Routing - Simple Examples

    This article contains a list of ruby on rails routing examples. If you find you have any questions please leave a comment. Routes are processed from the top of routes.rb down. If a route is matched it will stop processing the routes.rb file and use that r

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries