并行将数据添加到哈希图中 [英] Adding data to a hashmap in parallel

查看:89
本文介绍了并行将数据添加到哈希图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个std :: unordered_map实例作为某种数据库. (基本上,这只是一个常规的哈希图).
我有4个线程从网络中检索长字符串(我正在使用c ++ 11 std :: threads),并且在每个线程中,我标记它们接收的字符串.令牌化本身也可以使用新的Microsoft AMP库进行并行化(因此,令牌化的过程由GPU线程完成).

I've got an instance of an std::unordered_map serving as a database of some sort. (It's basically just a regular hashmap).
I have 4 threads retrieving long strings from a network (I'm using the c++11 std::threads) and within each of those threads, i tokenize the strings they receive. The tokenization itself is paralellized as well using the new Microsoft AMP library (so the process of tokenization is done by the GPU threads).

我希望4个主"线程中的每一个都将标记作为键添加到哈希图中,因为GPU线程完成了对字符串的标记化(然后重复该过程).

I would like each of the 4 "main" threads to add the tokens as keys into the hashmap as the GPU threads finish tokenizing the strings (and then repeat the process).

我该如何同步所有这些,以便可以从每个线程安全地将新密钥添加到数据库中?

How would i go about synchronizing all of this so that i can safely add new keys into my database from each of the threads ?

推荐答案

使用 查看全文

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