I/O完成端口问题 [英] I/O Completion Port Question

查看:74
本文介绍了I/O完成端口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用I/O完成端口为我的程序加载插件和处理插件.

问题是,当您创建Io Completion端口并尝试根据msdn将插件与之关联时,您需要为其赋予句柄,因为我只有插件的路径(我然后将它们与loadlibrary一起加载),我不能这样做

在这种情况下如何使用I/O完成端口? (即我没有文件或套接字,只需要抛出)


简而言之,我有很多插件需要动态加载,因此与其使用每个插件模型一个线程,不如使用io完成端口等可扩展性,但我不知道如何将插件与完成端口相关联(在每次加载之前)插件由结构表示)

I want to use a I/O completion port to load up plugins and process plugins for my program.

The problem is that when you create the Io Completion port and try to associate a plugin with according to msdn you need to give it handle since i only have the path to the plugins (i then load them with loadlibrary) i cant do this

how can i use I/O completion ports in this context? (i.e i dont have a file or sockets i just need throw)


In short i have lots of plugins i need to load dynamically so instead of using a 1 thread per plugin model i need to use something scalable like io completion ports but i dont know how associate a plugin with the completion port (before it is loaded every plugin is represented by a structure)

推荐答案

您是否尝试过使用WaitForSingleObject(hUploadHandle)
还是类似的东西?
Have you tried using WaitForSingleObject(hUploadHandle)
or something like that?


使用线程有什么问题?对我来说有2种选择:

1-您一对一地加载插件,并在进度栏中显示进度.
2-将插件加载到单独的线程中,并在线程完成后(加载插件后)立即更新进度条.

正如 Debijyoti 告诉您的那样,您可以在不同的线程上使用WaitForSingleObjectWaitForMultipleObjects来知道它们何时完成.

--------------------

正如Kurt Degiorgio所注意到的那样,该解决方案不适用于大量插件.然后,我将选择一个线程池:您可以创建10个线程,每个线程将加载多个插件,依此类推.
What is wrong with using threads? For me there are 2 options:

1- You load your plugins one by one in 1 thread and show the progression in a progress bar or something.
2- You load your plugins in separate threads, and as soon as a thread finishes (so as soon as a plugin is loaded), you update the progression bar.

As Debijyoti told you, you can use WaitForSingleObject or WaitForMultipleObjects on the different threads to know when they finish.

--------------------

As Kurt Degiorgio noticed, this solution is not suitable for a big numbers of plugins. I would then choose a pool of threads: you can create let''s say 10 threads, each of them will load several plugins, and so on.


如先前的文章所述,如果数量所需的线程数少于64,则应使用普通的线程模型来实现,但是如果线程数超过64,则效率将非常低.

waitformultpleobjects最多只能等待64个对象,此外,您将在上下文切换上浪费大量的CPU周期,例如在Windows平台上,完成端口是这种情况下的解决方法.

首先-返回并了解io编译端口(请检查MSDN)

第二-与正常情况下操作系统将工作项插入io编译端口(它们称为I/O数据包)不同,您需要使用提供的功能手动将它们插入(再次检查MSDN)

编辑-这是您需要查看的功能:

http://msdn.microsoft.com/en-us/library/aa364986%28v = vs.85%29.aspx [ ^ ]-从完成端口获取项目

http://msdn.microsoft.com/en-us/library/aa365458%28v = vs.85%29.aspx [ ^ ]-在io完成端口中插入一个项目
As previous posts suggested if the number of threads needed is less then 64 then you should implement it using the normal threading model but if the number of threads goes above 64 then this becomes very inefficient.

waitformultpleobjects can only wait on a max of 64 objects plus you will be wasting lots of cpu cycles on context switch''s as such on windows platforms completion ports are the way to go in this scenario.

first - go back and read about io compilation ports (check MSDN)

second - unlike in normal scenario where the OS will insert work items into the io compilation port(they are called i/o packets)you need to manually insert them using the provided functions (again check MSDN)

EDIT - here are the functions you need to look at:

http://msdn.microsoft.com/en-us/library/aa364986%28v=vs.85%29.aspx[^] - get an item from the completion port

http://msdn.microsoft.com/en-us/library/aa365458%28v=vs.85%29.aspx[^] - insert an item into the io completion port


这篇关于I/O完成端口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆