Windows Asynchronous IO Four Ways

Source: Internet
Author: User
We know that device io (files, pipes, sockets, and so on) is slow relative to other operations performed by the computer. So in the multithreaded structure, we take into account the asynchronous way to read and write the device, that is, we tell the system to read and write data to the device, while the other code of the application continues to execute until a system notification of the device operation is completed.
In the case of asynchronous Io, we first make IO requests to the system, the operating system queues various IO requests, and completes the operation internally, when the system is processing IO request, our thread can return to execute, when the operating system processing IO request, notify US data operation (send, receive, error) finished.
Windows provides four asynchronous IO technologies, the mechanism is almost the same, and the difference is in different ways of notifying results:
1, make a device kernel object into a signal
Windows considers a device handle to be a synchronized object, that is, it can be in a signal or in a signal-free State, when the device handle is created, the IO request is sent asynchronously, the handle is in a signal-free State, and when the asynchronous IO completes, the handle is trusted, The WaitForSingleObject or WaitForMultipleObjects function allows you to determine when a device operation is complete. The technology can only be used for one device to send only one IO request, otherwise, if a device corresponds to multiple operations, when the handle is believed to be unable to determine the operation of the device is completed. 2, make an event kernel object to have a signal
Bind a kernel event object for each I/O operation, and wait for the event wait function to wait for the event to be trusted, and when I/O is finished, the system makes the event bound to the operation trusted to determine that the operation is complete. This technique solves the problem of making a device kernel object into a signal technology, and one device can only correspond to one operation.
3. Warning I/O
In this technique, when a device IO request is issued, we are also required to pass a callback function called a completion routine, which is called when the IO request completes and completes the work we need to handle. This technique allows a single device to make multiple I/O requests at the same time.
4. Completion port
The completion of port technology is used to deal with large-scale requests, through the internal process pool technology can achieve high performance, at this time do not do in-depth discussion, if the prediction of the funeral, please see for yourself, or the next time to complete the port part decomposition.
Well, at this point, the knife grinding almost, the estimated also floated ~ ~ ~ ~, do business.

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.