Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在一个简单的示例c++;std::execution::par的程序 我在C++中学习并行执行,因为我偶然发现了这个简单的例子:_C++_Multithreading_Memory Leaks_C++17_Address Sanitizer - Fatal编程技术网

在一个简单的示例c++;std::execution::par的程序 我在C++中学习并行执行,因为我偶然发现了这个简单的例子:

在一个简单的示例c++;std::execution::par的程序 我在C++中学习并行执行,因为我偶然发现了这个简单的例子:,c++,multithreading,memory-leaks,c++17,address-sanitizer,C++,Multithreading,Memory Leaks,C++17,Address Sanitizer,test.cpp: #包括 #包括 #包括“/profile.h” #包括 int main(){ std::vector testSeq(10000000,std::rand()); std::向量测试平均值(10000000); std::copy(testSeq.begin(),testSeq.end(),testPar.begin()); { 日志持续时间(“seq”); 排序(testSeq.begin(),testSeq.end()); } { 日志持续时间(“par”); std:

test.cpp:

#包括
#包括
#包括“/profile.h”
#包括
int main(){
std::vector testSeq(10000000,std::rand());
std::向量测试平均值(10000000);
std::copy(testSeq.begin(),testSeq.end(),testPar.begin());
{
日志持续时间(“seq”);
排序(testSeq.begin(),testSeq.end());
}
{
日志持续时间(“par”);
std::sort(std::execution::par,testPar.begin(),testPar.end());
}
}
简介h:

#pragma一次
#包括
#包括
#包括
#包括
#包括
类日志持续时间{
公众:
显式日志持续时间(const std::string&msg=“”)
:消息(消息+“:”)
,开始(标准::时钟::稳定时钟::现在(){
}
~LogDuration(){
自动完成=标准::时钟::稳定时钟::现在();
自动dur=完成-启动;
std::ostringstream os;

os日志显示泄漏源于libtbb,但是您的程序没有显式使用libtbb。为什么要链接它?libstdc++需要链接tbb以实现并行性,不是吗?
std::vector testSeq(10000000,std::rand());
不会创建不同随机数的向量。它调用
rand()
一次,并将该值赋给向量的所有元素。@blastfurny,是的,我的错!谢谢你指出。尽管如此,它仍然工作得更快!