当前位置:网站首页>1. Introduction to threads

1. Introduction to threads

2022-08-09 09:32:00 come here my bear

program, thread, process

Overview

**Program:** A program is an ordered collection of instructions and data, which itself has no meaning of running, and is a static concept

**Process (Process): **Process is an execution process of executing a program and is a dynamic concept.is the unit of system resource allocation

**Thread (Thread): **Thread is an independent execution path and a unit of CPU scheduling and execution

Note:

  • Usually a process can contain several threads. Of course, there is at least one thread in a process, otherwise there is no meaning to save.
  • Many multi-threading is simulated, real multi-threading refers to having multiple CPUs, that is, multi-core, such as servers
  • If it is a simulated multi-threading, that is, in the case of one cpu, at the same time point, the cpu can only execute one code, because the switching is very fast, so there is the illusion of simultaneous execution

Summary

  • Threads are independent execution paths
  • When the program is running, even if there is no thread created by itself, there will be multiple threads in the background, such as the main thread and the gc thread
  • main() is called the main thread, the entry point of the bit system, used to execute the entire program
  • In a process, if multiple threads are opened up, the running of the threads is scheduled by the scheduler. The scheduler is related to operating system secrets, and the sequence cannot be interfered by human beings
  • When operating on the same resource, there will be a problem of resource grabbing, and concurrency control needs to be added
  • Threads will bring additional overhead, such as cpu scheduling time, concurrency control overhead
  • Each thread interacts in its own working memory, improper memory control will cause data inconsistency
原网站

版权声明
本文为[come here my bear]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090923102033.html