In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
The fundamental concept of threads
The goal of introducing the process is to make multi-programs perform concurrently so as to improve the capital application rate and piecemeal throughput, while the introduction of threads is to reduce the time and space expenses paid by the program during concurrent implementation and improve the concurrent function of piecemeal operations.
The most direct understanding of threads is the "lightweight process", which is a fundamental unit of CPU fulfillment and the smallest unit of program fulfillment flow, consisting of thread ID, program counters, memory aggregators, and inns. The thread is an entity in the process, and it is the fundamental unit that is adjusted and distributed by piecemeal independence. The thread itself does not have piecemeal capital, but only has a little capital in operation, but it can share all the capital of the process with other threads that belong to the same process. One thread can create and cancel another thread, and multiple threads in the unified process can perform concurrently. Because of the mutual restriction between threads, there is continuity in the operation of threads. There are also three basic forms of thread: improper, congested and running.
After the introduction of thread, the extension of the process has been changed, the process is only used as the allocation unit of piecemeal capital except CPU, and the thread is used as the allocation unit of the processor.
Analogy between thread and process
1) dispensing. In the traditional operation piecemeal, the fundamental unit with capital and independent adjustment is mostly the process. In the operation piecemeal of introducing thread, thread is the fundamental unit of self-adjustment, and process is the fundamental unit of capital. In the unified process, thread switching does not trigger process switching. Stopping thread switching in a divergent process, such as switching from a thread in one process to a thread in another process, will trigger process switching.
2) having capital. Whether the traditional operation is piecemeal or there is a thread, the process is mostly the fundamental unit with capital, and the thread does not have piecemeal capital (and a little bit of capital), but the thread can visit the piecemeal capital of its subordinate process.
3) concurrency. In the operation of introducing threads, not only processes can perform concurrently, but also multiple threads can perform concurrently, so that the operation fragments have better concurrency and improve the throughput.
4) piecemeal expenses. Because when you create or cancel a process, you have to allocate or receive takeover capital for it, such as memory space, IWeiO equipment, etc., so the cost of operating piecemeal is much higher than that of creating or canceling a thread. Similarly, when stopping the process switching, it touches on the storage of the later performance process CPU situation and the setting of the new transfer to the process CPU situation, while the thread switching only needs to keep and set a large number of memory contents, which is very small. In addition, because multiple threads in the unified process share the address space of the process, the synchronization and communication between these threads can be easily completed, even without piecemeal intervention.
5) address space and other capital (such as open files): the address space of the process is independent of each other, the process capital is shared among the threads of the unified process, and the threads in a process are prejudiced about other processes.
6) Communication: interprocess communication (IPC) requires the assistance of process synchronization and mutual exclusion to ensure data divergence, while threads can directly read / write process data segments (such as global variables) to stop communication.
Properties of the thread
In the piecemeal operation of multithreading, the thread is regarded as the fundamental unit of independent operation (or adjustment). At this time, the process is no longer a fundamental executable entity. However, the process still has a form related to performance, and the so-called process is in the form of "performance". In practice, it means that a thread is performing in the process. The secondary properties of a thread are as follows:
Thread is a light entity, it does not have piecemeal capital, but each thread should have a unique identifier and a thread master block, which records the memory and stack of thread performance.
Different threads can perform the opposite program, that is, when a service program is misappropriated by different users, piecemeal operations are created for them to form different threads.
Each thread in the unification process shares the capital that the process has.
Thread is the self-regulating unit of the processor, and multiple threads can be performed concurrently. In the single CPU computer bits and pieces, each thread can occupy the CPU; instead. In the multi-CPU computer bits and pieces, each thread can occupy different CPU at the same time. If each CPU works for each thread in a process at the same time, it can prolong the processing time of the process.
After a thread is created, it begins its life cycle until it is terminated. during the life cycle, the thread will experience various morphological changes such as congestion state, stop state, running state and so on.
The completion method of the thread
Thread completion can be divided into two categories: user-level threads (User-LevelThread, ULT) and kernel-level threads (Kemel-LevelThread, KLT). Kernel-level threads are also called kernel-supported threads.
In user-level threads, all tasks related to thread governance are accomplished by the user program, and the kernel is not aware of the existence of threads. The user program can be designed into a multithreaded program by using the thread library. On weekdays, the user program starts from a single thread and starts running in that thread, and at any time it runs, a new thread running in the opposite process can be created by misappropriating a derived routine in the thread library. Figure 2-2 (a) illustrates the completion method of user-level threads.
In kernel-level threads, all the tasks of thread governance are accomplished by the kernel, and the program has no code to stop thread governance, as long as a programming interface to kernel-level threads. The kernel protects context information for the process and every thread outside it, and tuning is also done on the basis of the kernel's thread-based architecture. Figure 2-2 (b) illustrates the completion of kernel-level threads.
In some bits and pieces, multithreading is done using the combinatorial method. Thread creation is completed in user space, and thread tuning and synchronization are stopped in the user program. Multiple user-level threads in a user program are mapped to kernel-level threads (less than or equal to the number of user-level threads). Figure 2-2 (c) illustrates the combination of the user level and the kernel level.
Figure 2-2 user-and kernel-level threads
Multithreaded mold
Some bits and pieces support the multithreading model of user thread and kernel thread at the same time, that is, to complete the connection between user-level thread and kernel-level thread.
1) many to one model
Multiple user-level threads are mapped to a kernel-level thread, and thread governance is completed in user space.
In this form, user-level threads have a stereotype of piecemeal operations.
Strengths: thread governance is stopped in user space, so it is more effective.
Defect: when a thread is choked while using kernel services, the whole process will be choked; multiple threads cannot run on multiple processors in parallel.
2) one-to-one mold
Map each user-level thread to a kernel-level thread.
Advantage: when one thread is choked, the other thread is allowed to continue to perform, so concurrency is stronger.
Defect: each user-level thread needs to create a kernel-level thread corresponding to it, so the cost of creating a thread is relatively large, which will affect the function of the program.
3) many-to-many models
Map n user-level threads to m kernel-level threads and request m
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.