使用Boost Thread在具有不同输入的多个线程上运行一个函数
using Boost Thread for running a function on multiple threads with different input
假设我有一个函数,它返回一个映射:
std::map<std::string,std::string> functionname(string abc123)
我怎么能通过不同的字符串相同的函数在单独的线程使用boost线程?(返回值存储在不同的变量中)
int main()
{
string param1 = ...;
string param2 = ...;
typedef std::map<std::string,std::string> RetT;
boost::future<RetT> f1 = boost::async(boost::launch::async,
boost::bind(functionname, param1));
boost::future<RetT> f2 = boost::async(boost::launch::async,
boost::bind(functionname, param2));
// here they run....
RetT r1 = f1.get(); // waits for f1
RetT r2 = f2.get(); // waits for f2
// Here we have the results in r1 and r2
}
相关文章:
- 使用基类中的派生方法运行线程,而无需使用模板
- 使用 ubuntu 终端在 c++ 上运行线程类的问题
- 将项目添加到队列时运行线程
- 运行线程和线程对象之间的关系
- 在 gtest 中运行线程
- 是否有一种可接受的运行线程或按顺序执行的方法
- 从类中运行线程
- 如何在第三方函数调用之前同时运行线程
- 在优先级最低的核心中运行线程
- 在C++中并行运行线程
- 在C 11中的背景中运行线程
- 在运行线程中处理事件
- 使用对象生存期运行线程
- WINAPI CreateThread并不总是运行线程
- 树莓派与 c++ 运行线程,在网络上发布数据
- 使用变量类型 std::function 运行线程
- Eclipse CDT 多线程调试不是最佳的 - 如何以独占方式运行线程
- 在 C 语言的后台运行线程
- 正在运行线程
- 在远程计算机上运行线程