1. Synchronous and Asyncronous

Synchronous and asynchronous are commonly used to describe a method call. Once a synchronous call has started, the caller must wait until the method returns before proceeding; An asynchronous call is more like a message passing, where the called method returns immediately and the caller can proceed. As shown in the figure, a synchronous call blocks subsequent steps in the current thread, while an asynchronous call puts the operation in another thread without blocking the caller’s subsequent work. From the perspective of the caller, an asynchronous operation seems instantaneous.


2. Concurrency and Parallelism

Concurrency and parallelism are two confusing concepts, both of which literally mean multiple tasks being executed simultaneously. But concurrency generally refers to multiple tasks running alternately (perhaps sequentially), while parallelism is true simultaneous execution.


3. The critical region

A critical section is used to represent a common resource (also known as shared data) that can be used by multiple threads, but only one thread can access it at a time. When a common resource is owned by one thread, other threads that need to use the resource must wait. Like a pay phone, only one person can use it at a time. After user A enters the phone booth to make a call first, the person behind user B must wait outside the phone booth (the actual situation is more complicated, for example, the person behind user B may not occupy resources in the order of first come, first come, later explained). When user A finishes the call, the person behind user B can use the phone booth. In concurrent programs, critical section resources need to be protected, and if b says something to a’s caller, there may be a lot of trouble.

4. Blocking and non-blocking

Blocking and non-blocking are commonly used to describe interactions between multiple threads. For example, if a thread enters a critical area and occupies a common resource, then other threads that need the resource must wait outside the critical area. This will cause the waiting thread to hang, and the thread can’t perform subsequent operations, which will cause blocking. At this point, if the thread holding the resource does not release the resource, then the thread outside the critical area will not be able to continue to work. Non-blocking, on the other hand, is a thread that does not wait on a critical section, but instead tries to keep executing forward.

Deadlock, Starvation, and Livelock

Deadlocks, starvation, and live locks all make it difficult for the thread to proceed. Deadlocks are the worst. In the most serious cases, the entire program cannot be executed properly. The following figure shows the occurrence of a deadlock.