关于IOCP的一个问题
如果我想使用完成端口从不同线程获取信息,
我该如何设计程序的结构?下面的怎么样?
如果我想使用全局函数,如何设置互斥体?
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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个解决方案:
您可以在没有任何关键部分的情况下完成它! 您所需要的只是保证“开始另一个文件操作();” 关闭相应的IOCP后不会被调用。
Try this solution:
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.
Push Framework,http://www.pushframework.com 也采用了这种设计,只不过多了一个线程接受传入连接。
Push Framework, http://www.pushframework.com uses this design too, except that it adds another thread to accept incoming connections.