C++ 如何在C+中使用多个光纤+;——就像一个纤维向量
我想让多条光纤像这样运行C++ 如何在C+中使用多个光纤+;——就像一个纤维向量,c++,c++11,boost,C++,C++11,Boost,我想让多条光纤像这样运行 #include <boost/fiber/fiber.hpp> #include <vector> void printNum(int i) { std::cout << i << std::endl; } void handleInts (std::vector<std::unique_ptr<int>>& ints) { std::vector<boost
#include <boost/fiber/fiber.hpp>
#include <vector>
void printNum(int i) {
std::cout << i << std::endl;
}
void handleInts (std::vector<std::unique_ptr<int>>& ints) {
std::vector<boost::fibers::fiber> runningFibers;
for (auto& integer : ints) {
runningFibers.emplace_back(boost::fibers::fiber([&](){ printNum(*integer);));
}
}
int main() {
std::vector<std::unique_ptr<int>> ints;
auto firstInt = std::make_unique<int>(1);
auto secondInt = std::make_unique<int>(2);
ints.emplace_back(std::move(firstInt));
ints.emplace_back(std::move(secondInt));
handleInts(ints);
return 0;
}
#包括
#包括
void printNum(int i){
std::cout内存泄漏是完整程序的属性,而不是片段。你能发布完整程序吗?理想情况下不要将代码放在main
中,因为main中有奇怪的静态生命周期规则,我认为这不是问题的核心。好吧,所以我编辑了它以提供更多的上下文。实际上,我没有使用整数使用协议缓冲区,但这不是我心目中的核心问题。如果需要的话,我可以模拟一个。只要你的示例演示了漏洞,这就是关键部分,这样其他人就可以使用你的代码并确认它,而不必发明可能会或可能不会解决你的问题的代码。:)增强上下文(依赖项)valgrind有一个记录在案的问题,需要使用一个名为“valgrind=on”的选项重建库。这可能是您的错误的来源吗?哦,是的,实际上可能是。我将尝试找出我是否可以做到这一点。