Synchronization refers to the communication mode in which the sender sends a packet only after the receiver sends a response.
Asynchronous means that the sender sends the next packet instead of sending the response from the receiver.
Csdn has discussed:
Http://expert.csdn.net/Expert/topic/2646/2646592.xml? Temp =. 3842584.
Http://expert.csdn.net/Expert/topic/2659/2659726.xml? Temp =. 1480219.
---------------------------------------------------------------
An inappropriate example is as follows:
Sendmessage (...)
Trace0 ("just like send ");
Postmessage (...)
Trace0 ("just like wsasend using overlapped ");
Sendmessage is not returned when the call is made. trace0 is executed only after the message is returned. This is synchronization.
Postmessage is returned immediately after the call, and trace0 is executed without message response. This is asynchronous.
Answer 3:
Differences between synchronous and asynchronous
For example: Normal B/S mode (synchronous) Ajax technology (asynchronous)
Synchronization: submit a request, wait for the server to process, and return the result. The client browser cannot do anything during this period.
Asynchronous: requests are triggered through events-> server processing (this is what the browser can do)-> processing is complete
Bytes --------------------------------------------------------------------------------------------------------------------
Synchronization means that you ask me to go to dinner. When I hear it, I will go to dinner with you. If I don't hear it, you will not stop calling until I tell you to hear it.
Asynchronous mode means that you call me and then eat on your own. After receiving the message, I may leave immediately or wait until I get off work.
Therefore, if I want to invite you to dinner, I will use the synchronous method. If I want to invite you to dinner, I will use the asynchronous method, so that you can save money.
Bytes --------------------------------------------------------------------------------------------------------------------
For example, synchronous message sending during a call is asynchronous.
-------------------------------------------------------------
Concepts of synchronous, asynchronous, blocking, and non-blocking
During network programming, we often see four call Methods: synchronous, asynchronous, blocking, and non-blocking. These methods are not easy to understand. The following is my understanding of these terms.
Synchronization
The so-called synchronization means that when a function call is sent, the call will not return until the result is not obtained. According to this definition, most functions are called synchronously (such as sin and isdigit ). But in general, when we talk about synchronization and Asynchronization, we are referring to the tasks that require the collaboration of other components or a certain amount of time. The most common example is sendmessage. This function sends a message to a window. This function does not return a message before the recipient finishes processing the message. After the other party completes processing, the function returns the lresult value returned by the message processing function to the caller.
Asynchronous
Asynchronous concept and synchronization relative. When an asynchronous process is called, the caller cannot obtain the result immediately. After the call is completed, the caller is notified by status, notification, and callback. Take the casycsocket class as an example (note that csocket is derived from casyncsocket, but the function has been converted from Asynchronous to synchronous). When a client sends a connection request by calling the connect function, the caller's thread can run down immediately. After the connection is established, the socket underlying layer sends a message to notify the object. The Execution Component and caller can return results in three ways: Status, notification, and callback. Which one can be used depends on the implementation of the execution part, unless the execution part provides multiple options, it is not controlled by the caller. If the execution part is notified by the status, the caller needs to check the status at intervals, which is very inefficient. (Some new programmers prefer to use a loop to check the value of a variable, this is actually a very serious error ). If you use the notification method, the efficiency is very high, because the execution of components almost do not need to do additional operations. As for the callback function, there is actually no much difference with the notification.
Blocking
Blocking call means that the current thread will be suspended before the call result is returned. The function is returned only after the result is obtained. Some people may equate blocking calls with synchronous calls. In fact, they are different. For synchronous calls, the current thread is still activated in many cases, but the current function does not return logically. For example, we call the receive function in csocket. If there is no data in the buffer zone, this function will wait until data is returned. At this time, the current thread will continue to process a variety of messages. If the main window and the calling function are in the same thread, the main interface should be refreshed unless you call the function in special interface operations. Another function Recv used by socket to receive data is an example of blocking calls. When the socket works in blocking mode, if the function is called without data, the current thread will be suspended until there is data.
Non-blocking
The concept of non-blocking corresponds to blocking, which means that the function will not block the current thread and return immediately before the result cannot be obtained immediately.
Object blocking mode and function calling
Whether the object is in blocking mode is highly correlated with whether the function is blocked or not, but it is not one-to-one. Blocking objects can have non-blocking calling methods. We can use certain APIs to poll the status and call the blocking function as appropriate to avoid blocking. For non-blocking objects, calling special functions can also be blocked. The select function is an example.
Understanding synchronization and Asynchronization