A question on IOCP
-
09-09-2019 - |
Question
If I want to use completion port to get information from different thread ,
how can I design the structure of the program?How about the one below?
If I want to use a global function ,how can I set the mutexes ?
Main(){
for i in range NumOfThreads{
CreateIoCompletionPort()
CreatThread(ThreadFun)
}
}
ThreadFun(){
While(1){
GetQueuedCompletionStatus(); // wait for completion of an IO
Process What ever has completed ();
Start another file operation();
}
}
Solution
Try this solution:
Main(){
for i in range NumOfThreads{
CreateIoCompletionPort()
CreateThread(ThreadFun)
}
for i in range NumOfCallerThreads
CreateThread(ThreadCaller)
}
ThreadCaller(){
While(1){
Start another file operation();
}
}
ThreadFun(){
While(1){
GetQueuedCompletionStatus(); // wait for completion of an IO
Process What ever has completed ();
}
}
You can do it without any critical sections! All you need is a guarantee that "Start another file operation();" will not be called after closing corresponding IOCP.
OTHER TIPS
Push Framework, http://www.pushframework.com uses this design too, except that it adds another thread to accept incoming connections.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow