windows - IOCP loop termination may cause memory leaks? How to close IOCP loop gracefully -
I have a classic Iocp callback that regulates I / o pending requests, executes them, / P> < Previous> Then, I'll be somewhere in the code: And it just works perfectly. Now I have a question: Do I want to close the IOCP queue immediately without looking? (For example, the application should be exited) I mean: If I set is_iocp_active for 'wrong' then the next time GetquueuedCompletionStatus () will assign a new I / O request, which will be the final I / O request: It will return, leave the thread out and when a thread exits all pending I / O requests, then the system is simply canceled, according to MSDN. But the 'MyIoRequest' type of structure that I installed when calling ReadFile () can not be completely destroyed: the system has canceled the pending I / O request, but I Manually destroy the structures I have created or when I close the loop, I will leak out all pending I / O requests! So, how can I do this? Is it wrong to set that variable incorrectly to stop the IOPL loop? Note that even if I use the APC requests to prevent the Alertbread Thread, it will also happen. The solution that comes to my mind is to add each 'MiORAExt' structures to the queue / list, and then remove them when GetQueuedCompletionStatusEx returns, but it should not interfere because the NQ / DQ such MAYROinstant structures Should the process be interlocked? I have a misunderstanding that how to use IOPL Loop. Can anyone put some light on this subject? The way I usually close an IOP thread, shut down my own 'Please complete' In this way you can completely stop and process all pending completions and then close the threads. How to do this, Posting the Requested Completion Status () with 0 for Post byte, Closing Key and Pavilapled. This would mean that the full key is a unique value (you do not have a valid file or socket which is a zero handle / completion key). Close one of the steps to complete the steps, close your socket connection, or turn off, etc. Once all those are closed, you can not make any more complete packets, so that you can post your special '0' completion; Post one for each thread for your IOCP, once the thread gets the key to complete '0' which gets it out. struct MyIoRequest {OVERLAPPED o; / * ... other parameters ... * /}; Bool is_iocp_active = true; DWORD WINAPI Worker Procurement (LPVOID LPPRAM) {ULONG_PTR dwKey; DWORD dwTrans; LPOVERLAPPED io_req; While (is_iocp_active) {GetQueuedCompletionStatus (handles) lpParam, and dwTrans, and dwKey, (LPOVERLAPPED *) and io_req, WSA_INFINITE); // Note, I could use GetQueuedCompletionStatusEx () ^ ^ ^ and set it to // in the qualified status, so I can wake the thread with an ACP request from another thread! Printf ("Request an I / O"); // [process i / o request] ... // [request request] destroyed_request (io_req); } // [clear some stuff] return 0; }
MyIoRequest * io_req = allocate_request (... parameter ...); ReadFile (..., (overlapped *) io_req);
Comments
Post a Comment