Fried rice with processes and threads to tell you exactly what the hell, in the end what is the difference?

What processes and threads that have peach difference between them

First come the whole point of academic good living, ready to tell people in words

1. The concept of processes and threads (the process is a collection of various resources, the thread is scheduled to be executed on the physical CPU)

Tucao about: In fact, I was watching "modern operating system," the book made it clear there is no particular concept or definition of processes and threads, instead of "in-depth understanding of computing systems" (This book is about the principles of computer organization and computer architecture I have a lot of students confused) described a little clearer.

  1. Process (process): In the configuration application level concurrent programs, each logical process is a control flow, but also a process of running a program receiving container all the information needed to schedule and maintained by the kernel, with each It is related to the process address space. It is the smallest unit of the operating system deployment resources. Unlike a simple program, he more often what address space ah, program counter, a mess of things, the following would be more detail.
  2. Thread (thread): the thread is to run the logic control flow in the process context, the process is performed inside a branch, scheduled by the kernel. It is the task of mobilizing and basic unit of execution. Each thread has its own thread context, the thread comprising a unique integer ID (Thread ID, TID), stack, stack pointer, program counter, general purpose registers, and condition codes. All threads in a process running in the shared virtual address space of the entire process.

These two cores inside repeatedly mentioned is a very complex concept, the kernel is not accurate to say: the kernel is a program, but very bottom layer to that circuit. CSDN bloggers Shrimps _2018 the " Analysis of the operating system and the operating system kernel ," available at: https: //blog.csdn.net/qq_22847457/article/details/89203593

2. The relationship between processes and threads

Here Insert Picture Description

3. The process procedures, the thread of difference (for example to do with fried rice)

Program tells you how fry, fry the whole process is a process, a thread that is fried time to change the size of the fire, program counter address space is the egg.

Here Insert Picture Description

3.1 to start Fried Rice

Come and eggs with soy sauce, then spoon the whole process of change Britain a fire call process.

  1. The first step (this is plain text description of the program, the specific operation process): the ham slices, diced carrots, onion mince, beat the egg.
    ( Green onion, eggs, ham, carrots is the program counter, registers like a mess of things, address space should be loaded with rice bowl )
    Here Insert Picture Description
  2. The second step (procedure): hot oil pan, stir-fry the egg into the pot, pan fry were dries ( this operation very fine thread belongs ).
    Here Insert Picture Description
  3. Third Step: Hot oil pan, put green onion saute, followed by addition of ham, Luobu Ding, stir-fry 5 minutes quickly poured into the rice, fried evenly scattered. (Details of the operation belong to the thread)
    Here Insert Picture Description
  4. Step four: fried rice even after adding eggs, then add soy sauce, you can pan stir fry evenly. (I think it is the point of a takeaway fragrant, shoving another drink Happy Water)
    Here Insert Picture Description

3.2 dinner, remember to dig yourself a cup of cappuccino (lbwnb)

4. processes and threads difference in consumption of resources

  1. Process switching overhead and thread switching : each process has independent logic control the flow of information, address space and the program needs to run, and therefore have a greater cost to switch between programs; thread can be seen as a lightweight processes, threads share the same type of address space, each thread has its own independent with respect to other threads to run the stack and program counter, so small switching between threads overhead.
  2. The environment : can run multiple processes at the same time in the operating system, but the same process can have multiple threads simultaneously.
  3. Memory Allocation : The system will assign a different address space for each process at runtime; and thread, in addition to the CPU, the system will not allocate memory between threads, thread groups can all share the process address space.

5. Why has the process also select a thread

  1. Since the thread is more lightweight than the process , so they are easier than the process (ie faster) build and easier to undo. In many systems, create a thread to create a comparative process is 10-100 times faster. In a large number of threads dynamically and quickly modify when it is important.
  2. By these registration application into a plurality of sequential threads may run in parallel, so that the programming model is relatively simple.
  3. If multiple threads are CPU-intensive, so you do not get an increase in resistance, but if there are a lot of calculations and a large number of I / O processing with multiple threads allows these activities to overlap each other, and will speed up the application program execution speed.
  4. In the multi-CPU systems, multithreading is beneficial in such systems, the real parallel with the possible.

6. References

  1. CSDN bloggers kingdoooom of " The main difference between processes and threads (summary) " at: https: //blog.csdn.net/kuangsonghan/article/details/80674777 depth_1-utm_source = distribute.pc_relevant.none-task & utm_source = distribute? .pc_relevant.none-task

  2. CSDN bloggers Shrimps _2018 the " Analysis of the operating system and the operating system kernel ," available at: https: //blog.csdn.net/qq_22847457/article/details/89203593

  3. Jane tone Video: fried rice practice (this belongs to a hand search)

  4. In-depth understanding of computer systems (third edition of the original book) P682-768 (Chapter XII: Concurrent Programming)

  5. Modern operating systems (Fourth Edition) P48-P102 (Chapter II: processes and threads), P22 (1.5.1 operating system concepts process)

Here Insert Picture Description

Released eight original articles · won praise 22 · views 1782

Guess you like

Origin blog.csdn.net/qq_45877524/article/details/105207479