A comparative understanding of processes, threads, co-threads, enhancement, fibers, and Hyper-threading

Source: Internet
Author: User

1. Process

  Task, Job (Job,task,schedule): Before the concept of a process occurs, the process has such a title.

In order for multiple programs to be capable of concurrency (at the same time only one is running, but it feels like multiple simultaneous runs; Parallel (true multiple at the same time, not feeling like multiple)) execution, the operating system needs a structure to abstract and represent the operation of this program.

Characteristics:

1. The process is an abstract structure of the operating system for a running program.

2, process refers to the operating system can be run independently and as a resource allocation of the basic unit, by a set of machine instructions, data and stacks and other components can be run independently of the active entity.

3. The operating system can run multiple processes concurrently, and multiple processes can execute and exchange information directly concurrently.

4, the process is required to run a certain amount of resources, such as CPU, storage space and I/O devices.

2. Threads

Process is the basic unit of resource allocation, the process of scheduling involves more content (storage space, CPU,I/O resources, process site protection), scheduling overhead, in the concurrent switching process is less efficient. In order to make the scheduling more efficient, the basic unit of independent operation and Dispatch is proposed which is lighter than the process.

Characteristics:

1, the thread is lighter than the process.

2, the thread can run independently, independent scheduling, with resources (generally CPU resources, program counters, etc.).

3, thread scheduling can greatly reduce the cost of scheduling (relative to the process), the switch of the thread will not cause the process of switching.

4, the introduction of the thread to further improve the concurrency of the operating system, the thread can execute concurrently.

5. Multiple threads of the same process share the resources of the process (save a lot of work on site protection of resource scheduling).

3, co-process , a total line of procedures, coroutine

The process is a lightweight thread in user mode, and the operating system kernel is ignorant of the process. The scheduling of the co-processes is completely controlled by the application, regardless of the scheduling of the operating system.

Characteristics:

1. A thread can contain one or more threads.

2, the co-process has its own register context and stack, the co-scheduling switch, the register on the fine lines and stacks to save, in the handover back to restore the previous storage context and stack.

3, the process can retain the state of the last call, where there will be a variety of generators (generators are castrated association).

4, fiber process

The implementation of porting code under Windows is called fiber

Code portability has always been the focus of inter-platform interaction, and in the process of porting a referral program from UNIX to Windows, there are issues such as inconsistent threading stack management, structure and exception handling, which increases the difficulty and cost of porting. To help companies migrate their code to windows,microsoft faster and more correctly, fiber (Fiber) is added to the operating system.

Fiber and fiber contrast, characteristics:

1, the thread is implemented in the Windows kernel, the operating system will be based on the system's scheduling algorithm to the Fiber regulation regulation scheduling.

2, fiber is implemented in the user mode, the kernel is ignorant of the fiber path.

3, Fiber is a more lightweight thread, a thread can contain one or more fibers.

4, the kernel will be a fiber-preemptive scheduling, the thread can only execute one fiber at a time code (the specific implementation of which fiber is determined by the user scheduling algorithm)

5, fiber scheduling and the scheduling of the thread is not directly related to the operating system at any time may seize the fiber thread running right, unless the running fiber Cheng switch to another fiber, otherwise fiber will not run.

6. Windows has an API in which threads are converted to fibers or multiple fibers are created within the same thread.

finally add a split line: enhancement and hyper-threading are not the same thing as some of the above concepts.

5. Tube Process

About Critical resources:

A resource that allows only one process to access at a time;

Multiple processes can only mutually exclusive access to resources;

Access to critical resources requires synchronous operations, such as signal volume, which is a convenient and efficient process synchronization mechanism. However, the semaphore mode requires that each process accessing the critical resource have a wait and signal operation. This allows a large number of synchronization operations scattered in the process, not only to the system management trouble, but also due to improper use of synchronization operations lead to deadlock.

Enhancement was created to solve such problems.

The various software and hardware resources managed in the operating system can be used to describe the resource characteristics abstractly, that is, to characterize the resource with a small amount of information and the operations performed on the resource, ignoring their internal structure and implementation details. Use shared data structures to represent the shared resources in the system abstractly. The operation that is implemented on the shared data structure is defined as a set of procedures, such as request for resources and release of requests and releases. The process of requesting, releasing, and other operations on shared resources is achieved through this set of procedures for sharing data structures, which can also accept or block access to processes based on resource conditions, ensuring that only one process uses the shared resource at a time, so that all access to the shared resource can be managed uniformly. Implement critical resource mutex access. Enhancement is a resource management module for an operating system that represents a data structure for shared resources and a resource management program that consists of a set of procedures that implement operations on that shared data structure. Enhancement is called by the process that requested and released the critical resource. A pipe defines a data structure and a set of operations that can be performed (on that data structure) for a concurrent process, which synchronizes the process and alters the data in the pipe.

6. Hyper-Threading

Hyper-Threading is a technology on Intel's CPU design. A CPU physical core can execute only one thread at a time, while a thread's switchover consumes tens of thousands of cycles and is not efficient enough.

Hyper-Threading is the technology that implements the same CPU physical core at the same time that it can execute almost two threads.

This is why we often see the double CPU physical core in the Task Manager on Intel CPUs.

A comparative understanding of processes, threads, co-threads, enhancement, fibers, and Hyper-threading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.