Talk about synchronous asynchronous, blocking non-blocking

Source: Internet
Author: User
Background

Many people are not clear on the concept of synchronous asynchronous, blocking non-blocking, and there are several completely different views on the Internet, but there is a lot of controversy about this part.

The author also in this part confused, spent some time to get through this problem, the following is a personal understanding of some of the summary. I hope I can help you. 1. Common Concepts

Example: "I" Boil water (note: The subject here is "I", which is the who we are talking about) 1.1. Synchronous asynchronous 1.1.1. Example

Focus: Do I need to see if the water burns or not (note, "I" and "active" these two words) synchronization: "I" to take the initiative to see the water boil not asynchronous: Do not need "I" initiative to see the water boil, the kettle rang notice "i" 1.1.2. Concept

Abstract concept: The process by which the executor obtains the result (who: the executor): The thing performer takes the initiative to get the result asynchronous: The thing performer passively gets things result 1.2. Blocking non-blocking 1.2.1. Example

Focus: Before the water burns, "I" can do something else to block:
The water didn't boil, I kept waiting (blocked) I went to do other things, but once in a while to see the water boil not (see the time blocked) non-blocking:
The water did not boil, "I" went to mop the ground, and then watched the TV 1.2.2 after a while. Concept

Abstract concept: Whether the performer gets the result before it can do something else (who: the performer) is blocked: The performer can not do anything else before the result is not blocked: things that the performer will do before they get results 1.3. Summing up the synchronization must be blocked, but the length of time to block the problem.
I take the initiative to see the water boil (sync), water boil before I have been waiting (blocking): the whole block I actively see the water boil (sync), a moment to see the water boil (see the process is blocked): Local blocking asynchronous must be non-blocking:
I don't need to take the initiative to see the water boil (asynchronous), I can do anything (non-blocking) during the boiling. 2. Network Programming level

The main aspect of network programming is IO, so this is mainly about IO. This is actually in the UNIX Network programming Volume 1 6th IO multiplexing is very clear, suggest that you look, I quote some of the key points. Specific can find a book to see. 2.1. POSIX defines synchronous I/O operations that cause the request process to block until I/O operation completes; asynchronous I/O operations: does not cause the request process to block. 2.2. IO model

According to POXIX's definition, the five IO models in the following figure, in fact, the first four are synchronous IO.

2.3. Summary

Note: The Who is the process 2.3.1 here. The synchronous IO process proactively looks at the readiness of the IO events concerned and then performs the related actions when ready
Note: Process blocking occurs when Select/epoll/poll waits for an event and the process actively performs read-write
Note: The blocking of the process occurs when the data has not arrived (the device has not received the data), or is not ready (the kernel space and the user-space data copy is not completed) 2.3.2. Asynchronous IO

Asynchronous IO requires support from the underlying operating system kernel, such as the Linux AIO, Windows IOCP. Processes do not take the initiative to see the care of IO events, only need to be concerned about IO events, data buffer and to bind the callback function or signal directly to tell the kernel, the kernel found IO time is ready, call the callback function directly or send the binding signal
Note: IO event-related data, from the kernel directly copy data to user space (read asynchronously), or from user space copy to kernel space (asynchronous write) process passively perform data operations
Note: After the process received the kernel notification, in 1 bound data buffer has been data, the process directly related to the data processing can be.

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.