Process and Thread

Table of contents

1. Operating System

 Operating system positioning

2. What is Process/Task?

1. Process control block abstraction (PCB Process Control Block)

2. Important properties in PCB

 3. Concurrent programming

 3. Thread

1. What is a thread?

2. Why do we need threads?

3. The difference between processes and threads

4. The relationship between Java threads and operating system threads


1. Operating System (Operating System)

      The operating system is a collective name for a set of software that manages computer resources. Common operating systems currently include:Windows series, Unix series, Linux series, OSX series, Android series, iOS series, Hongmengetc.

 Operating system positioning

         

The operating system consists of two basic functions:
  1. Prevent hardware from being abused by spatio-temporal applications;
  2.  Provides applications with a simple and consistent mechanism to control complex and often disparate low-level hardware devices.

Second, This is the process/Task (Process /Task)

        A process is an abstraction of a running program by the operating system. In other words, the process can be regarded as a running process of the program; at the same time, within the operating system, the process is the basic unit of resource allocation by the operating system.

1. Process control block abstraction(PCB Process Control Block)

    To manage any real thing inside a computer, it needs to be abstracted into a set of related and integrated data. In the Java language, we can describe this feature through classes/objects.

2. Important properties in PCB

       In this way, each PCB object represents a real running program, that is, a process.

        The operating system organizes the PCB objects through this data structure, such as linear tables, search trees, etc., to facilitate the operation of add, delete, check and modify (CURD) during management.

 3. Concurrent programming

        (1) If there is only one CPU core, use round robin scheduling to execute multiple processes in sequence, macroscopically "simultaneously" ", microscopically, "carrying out one after another" is called "concurrency".

        (2) If there are multiple CPU cores, they will be executed simultaneously, which is called "Parallel". 

 3. Thread

1. The line is the same

        A thread is an "execution stream". Each thread can execute its own code according to the order. Multiple threads execute multiple codes "at the same time".

2, Why do we need threads

Neck, "并发编程" "demand".

       The development of single-core CPU has encountered a bottleneck. To improve computing power , requires multi-core CPU. Concurrent programming can make full use of multi-cores CPU resources. Some task scenarios require "wait IO", in order to wait a> IO can do some other work , also needs to use concurrency Programming.

Secondly, Although multiple processes can also implement concurrent programming, But threads are more lightweight than processes.

  1.   Creating threads is faster than creating processes.
  2.   Destroying threads is faster than destroying processes.
  3.    Scheduling threads is faster than scheduling processes.

Finally, Although threads are lighter than processes, But people are still not satisfied , so there is "thread pool "(ThreadPool) and "Coroutine "

(Coroutine)

3. The difference between processes and threads

  1. A process contains threads. Each process has at least one thread, that is, the main thread.
  2. There is no memory space shared between processes. Threads of the same process share the same memory space, ()Creating a new thread does not require opening up resource space
  3. A process is the smallest unit for system allocation of resources, and a thread is the smallest unit for system scheduling.
  4. Both can achieve "concurrent programming", and threads are more efficient.
  5. Processes are independent of each other, and threads may affect each other (thread safety, thread exceptions).

4. The relationship between Java ’s threads and operating system threads

        Threads are a concept in the operating system. The operating system kernel implements a mechanism such as threads, And provides some API for users to use ( such as Linux ’s pthread library). Java standard library< a i=12> Thread class can be regarded as further abstracting and encapsulating the API provided by the operating system .Similar to (JDBC).

                         

        Conclusion: The related sharing of processes and threads ends here. I hope it will be helpful to everyone’s learning. If you have any questions or different opinions, you are welcome to comment. District’s message, thank you for your support 

Guess you like

Origin blog.csdn.net/qq_61576108/article/details/134529163