Using boost::lambda with boost::thread
Using boost::lambda with boost::thread
我在 Boost 上的线程中使用 lambda 时遇到了问题。
代码应该将函数(字符串)的结果放在向量的指定索引中。
std::vector< string > results(size);
std::vector< boost::thread > threads;
for( int i = 0; i < size; i++ ) {
threads.push_back( boost::thread( results.at( i ) = getAString( x,y,zed ) ) );
}
我将如何在这里使用 Boost::lambda?
请不要提及使用 c++11 语法。 我被迫使用的系统无法支持支持 c++11 的编译器。 谢谢!
在您的情况下,我想知道 lambda 函数的好处是什么。C++中的 Lambda 最适合已填充容器上的 STL 算法。在您的情况下,您希望使用 lambda 填充向量results
,这不是库想要的那种东西。你可能会有一场艰苦的战斗。http://www.boost.org/doc/libs/1_49_0/doc/html/lambda.html#introduction
话虽如此,可以创建直接输入 rvalue 的 lambda:http://www.boost.org/doc/libs/1_49_0/doc/html/lambda/le_in_details.html#lambda.rvalues_as_actual_arguments虽然在您的情况下,我不确定可以采用组成字符串时使用的参数的固定函数有什么好处。
此外,我相信线程函数不能返回值,因此您的线程函数将不得不将results.at(i)
的位置作为参数。
相关文章:
- 无法将参数传递给 boost::thread 构造函数
- 如何使用boost.thread运行多个接收器,每个线程应该分配给每个接收器?
- 使用 boost::thread 运行函子,但析构函数被错误地调用
- thread_specific_pointer可以在哪些平台上工作而无需 boost::thread?
- 将 boost::thread 与 C++11 std::mutex 混合使用是否安全?
- 同时使用 boost.python 和 boost.thread 时出现编译错误
- Boost.thread代码在Ubuntu和Windows中表现出不同的行为
- Pointer to boost::thread
- Linux上多核计算的低性能(openMP、boost::thread等)
- boost - thread.join() halts the ui
- 将基类的引用传递给 boost::thread 并在派生类中调用虚函数是否有效
- Difference between boost::thread and std::thread
- std::thread是boost::thread的替代品吗?
- 将 boost/thread headers 与 clang++ (Windows) 一起使用时出现问题
- 在linux下使用boost::thread创建一个boost::asio工作线程
- 如何在Windows上的CodeBlocks中构建和配置boost.thread
- C++ ReadConsoleInput 不适用于 boost::thread
- Boost.Thread超时等待
- 如何使用boost::thread创建线程池
- 使用std::vector和boost::thread进行内存管理