1.2 The second function of the operating system — concurrency

Welcome to zobol by Computer Operating system

  • 1. What is concurrency? Is concurrency necessary?
  • 2. Does concurrency require a multi-core CPU?
  • 3. Does the multi-core CPU and single-core CPU affect the implementation of concurrency?
  • 4. Is the concurrency of the concurrency function absolute or relative?
  • 5. How is the concurrency of GPU graphics cards implemented?

On the basis of virtualization technology, we can implement concurrent functions.

Question 1: What is the concurrency function? Is concurrency necessary?

Roughly speaking, concurrency is the ability to do more than one thing simultaneously.

In reality, many problems we encounter can be calculated at the same time. If our computer operating system has the concurrent function, it can save time, such as the birth of GPU. In addition, many operations are time limited requirements, which requires us to do one thing at the same time, but also to constantly record the running time. The most common is the timer function.

Without concurrency, many real-time tasks cannot be accomplished by computer systems. We can't listen to music and surf the Internet at the same time.Copy the code

Question 2: Must you have a multi-core CPU for concurrency?

No, the concurrency function is based on virtualization technology, and the number of concurrent processes and threads is independent of the number of cpus. Even with a single CPU, the operating system can still use the concurrency function to realize multi-threaded synchronous operations.

Question 3: Do multi-core cpus and single-core cpus affect the implementation of concurrency?

But if a computer system has a multi-core CPU, the operating system can have a larger number of threads, which makes it better able to perform parallel and synchronous Internet listening. In addition, multi-core CPUS can realize absolute parallel computing.

For example, if you have two tasks, A takes 3 minutes and B takes 5 minutes. The operating system can make the user feel that the two tasks are running at the same time. However, the total running time of a single-core CPU must be greater than or equal to 8 minutes, while that of a multi-core CPU can be greater than or equal to 5 minutes.

After all, although hardware resources are virtualized, the total amount of hardware resources is still fixed. The computing power of a single-core CPU may not be less than that of a multi-core CPU, but the underlying layer cannot realize real multi-core computing, so it must actually be single-row computing.

Question 4: Is the concurrency of the concurrency function absolute or relative?

Most of the time it’s parallel relative to our human perception, but in a few cases it’s absolute.

If it is a single-core CPU, it must be unidirectional from the hardware level and cannot carry out parallel computing operations. But by constantly switching between threads, the operating system can achieve a kind of pseudo-parallelism that makes users feel as if they are running multiple threads at once. In fact, the bottom layer still calculates A for A while, and then stops and calculates B for A while, but the interval is too short for humans to feel.

In the case of multi-core cpus, the operating system can allocate two tasks to two computing cores, thus achieving absolute concurrency on the hardware layer. However, operating systems typically have far more threads than CPU cores, so in most cases multicore is also the relative concurrency provided by the operating system.

Whether true concurrency can be realized depends on whether the hardware layer can support parallel computing. The typical hardware parallel computing model is the GPUCopy the code

Question 5: How is GPU graphics card concurrency achieved?

GPU is our common use of graphics card, used for graphics calculation or matrix calculation. We usually buy a CPU with an integrated graphics card, without which our computer screen goes dark.

GPU is a special CPU, which is a matrix number of cores.

The graphics reality itself consumes a certain amount of computing power (actually a large proportion), and the early black-framed DOS interface was generally able to handle the linear computing power of the CPU itself. But the advent of modern interface visualization and various 3D games has led to the need for new parallel graphical computing capabilities.

Each two-dimensional image can be viewed as a matrix, and if we use one CPU to compute each matrix element in parallel, we can compute the entire image in the time it takes to compute one pixel.

GPU can be viewed as an integration of a matrixed number of CPU cores (for example, 300×500), each of which has limited computing power, with hardware optimization specifically for graphical matrix computing.

The GPU is the best example of parallelism, concurrency. The concurrency of operating system is mainly realized by the ideas of reuse, time slice rotation, thread process, virtual memory and multi-core CPU.Copy the code