Multi-thread synchronization \ asynchronous, blocking \ non-blocking

First, synchronous and asynchronous

    Definitions : synchronous and asynchronous communication mechanism concerned message (synchronous communication / asynchronous communication).

  • Synchronization is something you call, the caller must wait for the call to return the results to continue in the future execution.
  • Asynchronous, synchronous, and contrary, the results obtained will not understand the caller, but the call after the call originator is available to continue the subsequent operations, the caller to notify the caller through the shaped body, or to process the call back off function by

    For example: You go to the mall to buy something, you took a fancy to a cell phone, and stores that you can a phone, he went to the warehouse the goods, you have to wait in the store, can not leave, this is called synchronization. Now you buy a mobile phone fashion directly to Jingdong orders, the order is completed you can use to do other times (chase drama, playing the king, lol) and other goods to go sign ok. This is called asynchronous.

  • Once the synchronization method call, the caller must call the method returns to continue until the subsequent behavior.
  • Like an asynchronous method invocation messaging, once started, the method call returns immediately, the caller can continue the subsequent operations. And, usually asynchronous method in another thread, the "real" implementation of the. The whole process, not hinder the work of the caller

Synchronous execution :
Here Insert Picture Description
asynchronous execution :
Here Insert Picture Description
    through these two pictures you can clearly see the difference between them.

Second, blocking and non-blocking

  • Blocking call refers to the results before the call returns, the current thread is suspended. Only the calling thread does not return until after the result.
  • Before non-blocking call refers not get the results immediately, the call does not block the current thread. For synchronous calls, many times the current thread is still active state, but from the logic of the current function does not return it, ie synchronization wait doing nothing, in vain occupy the resources.

Third, the difference between the two categories

    Blocking and non-blocking emphasized that the state of the program while waiting for the result of the call (the message, the return value) of.

    Synchronous and asynchronous communication mechanism to emphasize that message (synchronous communication / asynchronous communication).

Published 25 original articles · won praise 7 · views 2131

Guess you like

Origin blog.csdn.net/qq_41506111/article/details/102837948