首页 \ 问答 \ 如何同时等待I / O完成端口和事件?(How can I wait on an I/O completion port and an event at the same time?)

如何同时等待I / O完成端口和事件?(How can I wait on an I/O completion port and an event at the same time?)

有没有可能的方法来实现这一目标?

例如,我有一个I / O完成端口,10个工作线程正在从中拉出任务。 每个任务都与一个对象相关联。 某些对象无法同时处理,因此如果一个线程正在使用其中一个对象而另一个线程执行需要此对象的任务,则第二个线程必须等待第一个完成。

作为一种解决方法,对象可以具有在发布时发出信号的事件。 如果一个线程被“卡住”,因为收到的任务需要一个锁定的对象,它可能会等待锁定的对象被释放,或者等待一个新的任务排队。 如果它接收到一个新任务,它将把它无法工作的任务推回到队列中。

我知道其他方法,但这似乎应该存在的功能。 这可以通过Windows API实现吗?


Is there any possible way to achieve this?

For instance, I have an I/O completion port that 10 worker threads are pulling tasks out of. Each task is associated with an object. Some objects cannot be worked on concurrently, so if one thread is working with one of these objects and a second thread pulls out a task that requires this object, the second thread has to wait for the first to complete.

As a work around, objects could have an event that gets signaled upon release. If a thread is 'stuck' because the task is received requires a locked object, it could wait on either the locked object to be released, or for a new task to be queued. If it picks up a new task, it will push the task it couldn't work on back into the queue.

I am aware of alternative approaches, but this seems like functionality that should exist. Can this be achieved with Windows API?


原文:https://stackoverflow.com/questions/11068839
更新时间:2023-10-19 16:10

最满意答案

当你看到这个过程并不是那么困难。 聚合“管道”就是这样,每个“阶段”将结果输入下一个进行处理。 就像unix“管道”:

ps -ef | grep mongo | tee out.txt

所以它只是添加阶段,实际上是三个$group阶段,其中第一阶段进行基本聚合,剩下的两阶段简单地“汇总”输出中所需的数组。

db.collection.aggregate([
    { "$group": {
        "_id": {
            "bookId": "$bookId",
            "store": "$store",
            "shelf": "$shelf"
        },
        "count": { "$sum": 1 }
    }},
    { "$group": {
        "_id": {
            "bookId": "$_id.bookId",
            "store": "$_id.store"
        },
        "shelves": { 
            "$push": {
                "name": "$_id.shelf",
                "count": "$count"
            }
        }
    }},
    { "$group": {
        "_id": "$_id.bookId",
        "stores": {
            "$push": {
                "name": "$_id.store",
                "shelves": "$shelves"
            }
        }
    }}
])

最后你可以$project_id更改为bookId ,但你应该已经知道它是什么,并习惯将_id作为主键处理。 这样的操作需要付出代价,因此这是一种习惯,你不应该从一开始就学会正确地做事。

所以这里真正发生的是,构成分组细节的所有字段都成为$group的主键,而另一个字段被生成为count ,以计算该分组中的货架。 认为SQL等价:

GROUP BY bookId, store, shelf

所有其他阶段都将每个分组级别转换为数组条目,首先是商店内的货架,然后是bookId中的商店。 每次主要分组键中的字段由进入生成的数组的内容减少。

当你开始考虑“管道”处理时,它就变得清晰了。 在构造一个表单时,然后获取该输出并将其移动到下一个表单,依此类推。 这基本上就是如何在两个数组中折叠结果。


The process isn't really that difficult when you look at at. The aggregation "pipeline" is exactly that, where each "stage" feeds a result into the next for processing. Just like unix "pipe":

ps -ef | grep mongo | tee out.txt

So it's just adding stages, and in fact three $group stages where the first does the basic aggregation and the remaining two simply "roll up" the arrays required in the output.

db.collection.aggregate([
    { "$group": {
        "_id": {
            "bookId": "$bookId",
            "store": "$store",
            "shelf": "$shelf"
        },
        "count": { "$sum": 1 }
    }},
    { "$group": {
        "_id": {
            "bookId": "$_id.bookId",
            "store": "$_id.store"
        },
        "shelves": { 
            "$push": {
                "name": "$_id.shelf",
                "count": "$count"
            }
        }
    }},
    { "$group": {
        "_id": "$_id.bookId",
        "stores": {
            "$push": {
                "name": "$_id.store",
                "shelves": "$shelves"
            }
        }
    }}
])

You could possibly $project at the end to change the _id to bookId, but you should already know that is what it is and get used to treating _id as a primary key. There is a cost to such operations, so it is a habit you should not get into and learn doing things correctly from the start.

So all that really happens here is all the fields that would make up the grouping detail are made the primary key of $group with the other field being produced as count, to count the shelves within that grouping. Think the SQL equivalent:

GROUP BY bookId, store, shelf

All each other stage does is transpose each grouping level into array entries, first by shelf within the store and then the store within the bookId. Each time the fields in the primary grouping key are reduced down by the content going into the produced array.

When you start thinking in terms of "pipeline" processing, then it becomes clear. As you construct one form, then take that output and move it to the next form and so on. This is basically how you fold the results within two arrays.

相关问答

更多
  • 如果创建一个按位置id索引的数组,则可以使用索引为指定位置添加子项: $locations_by_id = []; foreach($locations as $location) { $location['children'] = []; //initialize children to an empty array $locations_by_id[$location['id']] = $location; } foreach($rooms as $room) { / ...
  • 你的查询不太正确; 子聚合应该使用在匿名函数中作为aa的参数传递的AggregationContainerDescriptor Dim queryResults = elasticClient.Search(Of Mail)(Function(s) s. Size(0). Aggregations(Function(a) a. Filter("AutoComplete", Function(f) f. Filter(Function(ff) ff. Ma ...
  • 一种解决方案使用[].reduce()和[].map() : // eg: sumArrays([ [1,2,3,4], [5,6,7,8] ]);// <- outputs [6, 8, 10, 12] function sumArrays(arrays) { return arrays.reduce( function(memo, nums, i) { if(i == 0) return nums.concat(); else retu ...
  • 通过将.sortValues方法修改为以下方法解决了这个问题: .sortValues(function(a,b) { return priority_indicator_order.indexOf(a[ncca_ce_indic_plain]) - priority_indicator_order.indexOf(b[ncca_ce_indic_plain]); }) Fixed this by modifying the .sortValues method to the followin ...
  • For循环应该
  • 当你看到这个过程并不是那么困难。 聚合“管道”就是这样,每个“阶段”将结果输入下一个进行处理。 就像unix“管道”: ps -ef | grep mongo | tee out.txt 所以它只是添加阶段,实际上是三个$group阶段,其中第一阶段进行基本聚合,剩下的两阶段简单地“汇总”输出中所需的数组。 db.collection.aggregate([ { "$group": { "_id": { "bookId": "$bookId", ...
  • 我连接了真正的恒温器,将它添加到我的帐户中,现在我可以看到last_connection字段作为响应。 看起来我需要CONNECT REAL DEVICE才能看到这个字段。 我认为battery_health和ui_color_state字段也可用于真正连接的设备。 I've connected real thermostat, added it to my account and now I can see last_connection field in response. Looks like I n ...
  • 从tidyr::nest文档页面(重点介绍): nest()创建一个包含所有嵌套变量的数据框列表 :这似乎是实践中最有用的形式。 From the documentation page for tidyr::nest (emphasis mine): nest() creates a list of data frames containing all the nested variables: this seems to be the most useful form in practice.
  • 在得到答案之前,让我们首先以更一般的方式重写您的代码: ag = 3; % or agg_size X_agg = zeros(size(X)./[1 1 ag]); for i = 1:ag X_agg(:,:,i) = mean(X(:,:,(i-1)*ag+1:i*ag), 3); end 为了避免使用for循环,一个想法是将X矩阵reshape为可以直接使用mean函数的东西。 splited_X = reshape(X(:), [size(X_agg), ag]); 所以现在split ...
  • 您使用NEST客户端版本1.7.1按预期工作的聚合,如此示例所示 void Main() { var settings = new ConnectionSettings(); var connection = new InMemoryConnection(settings); var client = new ElasticClient(connection : connection); var response = client.Search(s => ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。