Concurrent, parallel, serial, synchronous, and asynchronous click through

1. Concurrent programming is also called multithreaded programming.

    In the program, there are often many time-consuming tasks, such as uploading files, downloading files, and chatting with customers that require a long time to establish a connection. At this time, one thread cannot serve multiple users, and there will be waiting problems due to resource monopoly. The essence of concurrency is the multiplexing of a physical CPU (or multiple physical CPUs) between several programs. Concurrency is to enforce multi-user sharing of limited physical resources to improve efficiency (concurrent purchase of tickets).
    Concurrency When there are multiple threads operating, if the system has only one CPU, it is impossible for it to perform more than one thread at the same time. It can only divide the CPU running time into several time periods, and then allocate the time periods to each Thread execution, when the thread code of a period of time is running, other threads are in a suspended state. . This approach is called Concurrent.

2. "Parallel" means that two or more events or activities occur at the same time. In a multi-program environment, parallelism enables multiple programs to be executed simultaneously on different CPUs at the same time. (Hadoop cluster is parallel computing)

    When the system has more than one CPU, thread operations may be non-concurrent. When one CPU executes a thread, the other CPU can execute another thread. The two threads do not occupy each other's CPU resources and can proceed at the same time. This method is called parallel (Parallel).

Concurrency and parallelism

    Concurrency and parallelism are two concepts that are similar and different. Parallel means that two or more events happen at the same time; and concurrency means that two or more events happen in the same time interval. In a multi-program environment, concurrency means that multiple programs are running at the same time macroscopically within a period of time, but in a single-processor system, only one program can be executed at a time, so these programs are only It can be executed alternately in time-sharing. If there are multiple processors in the computer system, these programs that can be executed concurrently can be distributed to multiple processors to achieve parallel execution, that is, each processor is used to process a program that can be executed concurrently. All programs can be executed at the same time.

3. Serial and parallel:

    Parallel and serial refer to how tasks are executed. Serial means that when there are multiple tasks, each task is executed in sequence, and the next one can only be carried out after one is completed. Parallel means that multiple tasks can be executed at the same time, and asynchronous is a prerequisite for multiple tasks in parallel.

4. Synchronous and asynchronous:

    Refers to whether a new thread can be opened. Synchronization cannot start a new thread, but asynchronous.
    Asynchronous: Asynchrony and synchronization are relative. Synchronization means sequential execution. After one is executed, the next is executed, which requires waiting and coordinated operation. Asynchrony means that they are independent of each other. They continue to do their own things while waiting for an event, and do not need to wait for the event to complete before working. Threads are a way to achieve asynchrony. Asynchrony means that the main thread that calls the method does not need to wait for the completion of another thread synchronously, so that the main thread can do other things.
    Asynchrony and multithreading are not an equal relationship. Asynchrony is the ultimate goal, and multithreading is just a means for us to achieve asynchrony. Asynchrony is when a call request is sent to the callee, and the caller can do other things without waiting for the return of the result. The realization of asynchronous can adopt multi-threading technology or hand it over to another process for processing.

5. Multithreading

    Multithreading is a logical concept of programming, which is a piece of code that runs concurrently in a process. Multithreading can realize switching execution between threads.

Guess you like

Origin blog.csdn.net/qq_41071754/article/details/114520902