Multithreading 关于IOCP的一个问题

Multithreading 关于IOCP的一个问题,multithreading,operating-system,iocp,Multithreading,Operating System,Iocp,如果我想使用完成端口从不同的线程获取信息 我如何设计程序的结构?下面的那个如何 如果要使用全局函数,如何设置互斥体 Main(){ for i in range NumOfThreads{ CreateIoCompletionPort() CreatThread(ThreadFun) } } ThreadFun(){ While(1){ GetQueuedCompletionStatus(); // wait for completion of

如果我想使用完成端口从不同的线程获取信息

我如何设计程序的结构?下面的那个如何

如果要使用全局函数,如何设置互斥体

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();
    }

}
尝试以下解决方案:

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 ();
    }
}
你可以在没有任何关键部分的情况下完成它!您所需要的只是保证“启动另一个文件操作();”在关闭相应的IOCP后不会被调用。

推送框架也使用此设计,只是它添加了另一个线程来接受传入连接