Old Zhang loves drinking tea, without talking nonsense, and boiling water.
Appearance character: Lao Zhang, two kettle (ordinary kettle for short; ring kettle for short ).
1. Old Zhang put the kettle on the fire and waited for the water to open. (Synchronization Blocking)
Lao Zhang thinks he is a bit silly.
2. Old Zhang put the kettle on the fire, went to the living room to watch TV, and went to the kitchen from time to see if the water was open. (Non-blocking Synchronization)
Lao Zhang still thought he was a little silly, so he became a high-end user and bought the kind of kettle that would sound the flute. When the water is turned on, it can send out loud noises ~~~~ Noise.
3. Old ZhangKettlePut it on the fire and wait for the water to open. (Asynchronous Blocking)
Lao Zhang thinks it is of little significance to be stupid.
4.KettlePut it on the fire, go to the living room to watch TV, don't watch it again before the kettle rings, then get the pot again. (Asynchronous non-blocking)
Lao Zhang thinks he is smart.
The so-called synchronous Asynchronization is only for the kettle.
Ordinary kettle, synchronous; kettle, asynchronous.
Even though they can work, the kettle can be completed by themselves, prompting Lao Zhang to open the water. This is not what ordinary kettle can do.
Synchronization only allows callers to poll themselves (in Case 2), resulting in low efficiency.
The so-called non-blocking is only for Lao Zhang.
Li and other old Zhang, blocking; watch TV Old Zhang, non-blocking.
In case 1 and case 3, Lao Zhang is blocked, and his daughter-in-law shouted that he did not know. Although the kettle in step 3 is asynchronous, it does not make much sense for lahang. Therefore, Asynchronization is generally used in combination with non-blocking operations, so as to make full use of Asynchronization.
Programmers write programs. In many cases, Lao Zhang and the kettle must be involved, that is, the caller and the called. The four combination modes have their own strengths.
This example is similar to the bank queuing, but I think it is easier to understand.
Lao Zhang is smarter than once, and I admit it is similar to Lao Zhang. At the beginning, the logic was simple, but the efficiency was low. With the gradual increase, the efficiency also increases. Therefore, I personally think that the program efficiency is inversely proportional to the degree of simplicity.
But it doesn't mean that asynchronous non-blocking is always the best. In some cases, synchronous or blocking is more suitable.