1 / 10

Win32 Programming

Where are we?. Last topic: I/O Completion PortsRemind me what we did last class

gaynell
Télécharger la présentation

Win32 Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Win32 Programming Lesson 27: I/O Completion Ports OUCH

    2. Where are we? Last topic: I/O Completion Ports Remind me what we did last class

    3. Threads (again) Concurrent model where a thread is created to handle the request Leverages thread pooling But it is *very* gnarly

    4. CreateIoCompletionPort HANDLE CreateIoCompletionPort( HANDLE hFile, HANDLE hExistingCompletionPort, ULONG_PTR CompletionKey, DWORD dwNumberOfConcurrentThreads); Pretty confusing, as it does two things

    5. Step 1 HANDLE CreateIoCompletionPort( INVALID_HANDLE_VALUE, NULL, 0, dwNumberOfConcurrentThreads); Creates a new port with dwNumberOfConcurrentThreads (max) What do you notice missing from typical Kernel Object calls?

    6. Step 2 Associate a Device with this port CreateIoCompletionPort( hDevice, hCompletionPort, dwCompletionKey, 0); Next, create 2*CPU threads

    7. Per Thread Wait for requests, putting yourself to sleep in the process BOOL GetQueuedCompletionStatus( HANDLE hCompletionPort, PDWORD pdwNumberOfBytesTransferred, PULONG_PTR pCompletionKey, OVERLAPPED ** ppOverlapped, DWORD dwMilliseconds); Which port are we monitoring? How long to sleep for?

    8. Example DWORD dwNumBytes; ULONG_PTR CompletionKey; OVERLAPPED * pOverlapped; BOOL bOk = GetQueuedCompletionStatus(hIOCP, &dwNumBytes, &CompletionKey, &pOverlapped, 1000); DWORD dwError = GetLastError; if (bOk) { // IO Request OK } else { if (pOverlapped !=NULL) { // We failed } else { if (dwError == WAIT_TIMEOUT) { // We timed out } else { // Bad call to fn } } }

    9. Note IO Completion Requests are FIFO (why?) Thread awakenings are LIFO (why?) Vista allows you to retrieve multiple requests at once (why is this helpful?) GetQueuedCompletionStatusEx(); And now we get to the point How this works when a thread goes to sleep

    10. Dont Need a Real Completion BOOL PostQueuedCompletionStatus( HANDLE hCompletionPort, DWORD dwNumBytes, ULONG_PTR CompletionKey, OVERLAPPED* pOverlapped); Very neat way to do this and has lots of other uses Vista: CloseHandle (hCompletionPort) wakes all threads and returns FALSE with ERROR_INVALID_HANDLE

    11. Congratulations YOU HAVE COMPLETED ALL YOUR NEW MATERIAL Every single person who stuck with me this class has done well!

More Related