The concept of synchronous Asynchrony (Ajax is asynchronous, C # is synchronous)

Source: Internet
Author: User

Process synchronization is used to realize the reproducibility of program concurrency execution. A The concept of process synchronization and Asynchrony 1. Process synchronization: When a function call is made, the call does not return until the result is obtained. That is, you have to do one thing, and wait until you have finished before you can do the next thing. Just like waking up in the morning, wash first, then can eat, not in the wash did not finish, began to eat. By this definition, the vast majority of functions are synchronous calls (such as sin,isdigit, etc.). But generally speaking, we are talking about synchronous and asynchronous tasks, especially those that require other components to collaborate or need to be done in a certain amount of time. The most common example is SendMessage. The function sends a message to a window that does not return until the other party finishes processing the message. When the other party finishes processing, the function returns the LRESULT value returned by the message handler function to the caller. 2. The concept of asynchronous async is relative to synchronization. When an asynchronous procedure call is made, the caller cannot get the result immediately. The part that actually handles the call notifies the caller via status, notification, and callback after completion. Take the Casycsocket class as an example (note that CSocket derives from CAsyncSocket, but its functionality has been converted from asynchronous to synchronous), and when a client makes a connection request by calling the Connect function, the caller thread can run down immediately. When the connection is actually set up, the bottom of the socket sends a message informing the object. It is mentioned here that the executing parts and callers return results in three ways: status, notifications, and callbacks. Which one can be used depends on the implementation of the execution part, which is not controlled by the caller unless the execution part provides multiple choices. If the execution part is notified by the state, then the caller needs to check every time, the efficiency is very low (some beginners of multithreaded programming, always like to use a loop to check the value of a variable, which is actually a very serious error). If you are using notifications, the efficiency is high because there is almost no extra action required to execute the part. As for the callback function, there is not much difference from the notification. The basic concept of process synchronization in computer systems, due to the limited resources, which leads to the competition and sharing of resources between processes, the concurrent execution of the process is not only the randomness of the execution start time of the user program and the result of improving the resource utilization. It is also caused by the restriction of resource competition and sharing on the process of implementation. So, what are the constraints in the concurrent execution of the process? Two Synchronous and asynchronous transfers: 1. Asynchronous transfers Typically, asynchronous transfers are in the character transmission unit, each character is appended with the  1  bit start bit and the  1  stop bit to mark the beginning and end of a character, and to achieve data transfer synchronization. The so-called asynchronous transfer refers to the character and character (the end of a character to the beginning of the next character) betweenTime intervals are variable and do not need to strictly limit their time relationships. The starting bit corresponds to a binary value of 0, denoted by a low level, and occupies the  1  bit width. The stop bit corresponds to the binary value  1, which is represented by a high level, which occupies the  1~2  bit width. A character occupies the  5~8 bit, depending on the character set used by the data. For example, the Telegraph code character is  5  bit, ASCII character is  7  bit, Chinese character code is 8  bit. In addition, the  1  bit parity bit is attached, and it is possible to choose odd or even parity to implement simple error control for the character. In addition to the same data format (the number of bits of the character, the number of bits in the stop bit, the check digit and the check mode, etc.), the transmitting end and the receiving end should adopt the same transmission rate. Typical rates are: 9 b/S, 19.2kb/s, 56kb/s and so on. Asynchronous transmission, also known as the end-to-end asynchronous communication, has the advantage of being simple and reliable and suitable for character-oriented and low-speed asynchronous communication situations. For example, the communication between a computer and a modem is this way. Its disadvantage is that the communication overhead, each transmission of a character to be additional two or three bits, communication efficiency is low. For example, when using a modem to surf the Internet, the general sense of speed is very slow, in addition to low transmission rate, and communication overhead, low communication efficiency is closely related. 2.  synchronous transmission Typically, a synchronous transfer is a data block for the transmission unit. The head and tail of each block are appended with a special character or sequence of bits, marking the beginning and end of a block of data, and typically attaching a checksum sequence   (such as a 16-bit or 32-bit CRC checksum) to control the data block. The so-called synchronous transmission refers to the time interval between the data block and the data block is fixed, and must strictly stipulate their time relationship. Three Synchronous blocking and asynchronous blocking: Synchronization is blocking mode, asynchronous non-blocking mode.   My understanding: Synchronization refers to the two-thread run being related, where one thread blocks waiting for another thread to run. Async means that two threads are irrelevant and run their own.   synchronization means that after the sender sends out the data, the receiver sends back the response before sending the next packet to the communication mode.   Async means that after the sender sends out the data, it waits for the receiver to send back the response, and then sends the next packet's communication mode.   A less appropriate example, like:  sendmessage (...)  trace0 ("Just  like  send");  postmessage (...)  trace0 ("JUST&NBsp; like  wsasend  using  overlapped ");   sendmessage is not returned at the time of the call, Wait for the message to respond before executing the TRACE0, which is the synchronization.  postmessage is returned immediately after the call and executes TRACE0 without a message response, which is asynchronous. Four. Other explanations:  the difference between synchronous and asynchronous   For example: normal B/s mode (synchronous) Ajax Technology (asynchronous) synchronization: Submit request, wait for server processing, processing complete return   This period the client browser cannot do anything asynchronously:   Request through event triggering server processing (this is the browser can still do other things) and processing completed synchronization is that you told me to eat, I heard and you go to dinner, if not heard, you keep barking until I told you to hear, to eat together. Async is you call me, and then go to dinner, I can get the news immediately, may wait until after work to eat. So, if I ask you to eat in a synchronized way, ask me to eat with the Async method, so you can save money. For example   sync   send messages on call is asynchronous  

The concept of synchronous Asynchrony (Ajax is asynchronous, C # is synchronous)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.