草庐IT

thread_pool_size

全部标签

c++ - 支持多态的Stored-by-Value Pool,如何使用智能指针?

介绍我有一个数据结构:值池。(不是指针池)当我调用create()时,它会返回Handle。到目前为止一切都很好。templateclassPool{std::vectorv;//storebyvalueHandlecreate(){....}}templateclassHandle{Pool*pool_;//pointerbacktocontainerintpool_index_;//whereIaminthecontainerT*operator->(){returnpool_->v.at(pool_index_);//i.e."pool[index]"}voiddestroy()

c++ - 使用省略号的回退函数 : can we force the size of the parameters pack?

考虑以下代码:#include#includestructS{templateautof(A&&...args)->decltype(std::declval().f(std::forward(args)...),void()){std::coutvoidf(...){std::cout(42);//->hasf(int)s.f(42);//->hasnotf(int)//oopss.f();//->hasnotf(int)}如示例所示,对f的第三次调用工作正常,即使参数数量错误,因为对于回退函数来说它根本没有错.当以这种方式涉及省略号时,有没有办法强制参数的数量?我的意思是,我可以在

c++ - std::span.size() 与数组/vector 大小

我们在工作中使用std::span()(目前使用gsl实现)。最近我们发现将std::span.size()与vector.size()进行比较会产生-Wsign-compare错误:if(span.size()>vector.size())//comparisonbetweensignedandunsignedintegerexpressions[-Wsign-compare]我认为我们不想对这些比较中的每一个进行转换。我们的编码指南将这些警告视为错误。想知道是否有人有任何想法或建议? 最佳答案 您可以使用迭代器并同时使用函数st

c++ - boost::asio 和 boost::thread 的错误使用

我正在使用boost::asio和boost::thread来实现接受消息的消息服务,如果有,则异步发送它们没有正在处理的消息,或者如果有正在处理的消息,则排队该消息。消息率在我看来很高,大约每秒2.000条消息。有这么多消息,我很少遇到损坏的消息。在2.000封邮件中,大约有4-8封已损坏。我认为问题是由于错误使用了boost::asio和/或boost::thread库造成的。我实现的代码主要是基于thisboosttutorial.我找不到错误,并且由于主要消息已解决,所以我很难缩小问题的范围。也许其他人知道这里出了什么问题?基本上这个类的使用方式如下:(1)在我的程序开始时调用

c++ - 在 VS2010 中使用 Boost.Pool - 链接器错误

Boost.Pooldocumentation说(强调我的):TheBoostPoollibraryisaheader-onlylibrary.Thatmeansthereisno.lib,.dll,or.sotobuild;justaddtheBoostdirectorytoyourcompiler'sincludefilepath,andyoushouldbegoodtogo!但是当我尝试在VS2010SP1中编译这样的代码时:#include#include#includeintmain(){typedefstd::basic_string,boost::pool_allocat

c++ - boost::thread 和 std::thread 之间的区别

我有一个使用boost::thread的地方(例如使用boost::asio)std::vector>threads;for(std::size_ti=0;ithread(newboost::thread(boost::bind(&boost::asio::io_service::run,io_services_[i])));threads.push_back(thread);}如果我尝试将它与std:thread一起使用,我会得到编译错误:std::vectorthreads;for(std::size_ti=0;iioServices.size();++i){std::thread

c++ - Valgrind 在空析构函数上给出 "Invalid write of size 8"

我有一个声明:std::map*myMap;进入某个类A。这个映射是在A的构造函数中创建的:myMap=newstd::map;MyClass类基本上是一个结构,用于存储一些带有一些getter/setter的数据。MyClass中没有任何指针或新实例,只有一对枚举值、一个无符号整数和一个bool值。所以MyClass析构函数是空的。另一方面,在A的析构函数中我正在删除映射:A::~A(){if(myMap!=NULL){deletemyMap;myMap=NULL;}}这里Valgrind在删除行上告诉我“地址0x4c389b0是一个大小为48的block内的16个字节free'd[

c++ - size_t 和 __w64、time_t 和 __int64 是如何工作的?

我不是C或C++的老手。我不知道time_t是如何定义和设计的。几个帖子,例如:Whatisultimatelyatime_ttypedefto?Whatissize_tinC?Differencebetweensize_tandstd::size_t但是这些帖子只说明什么是time_t或size_t。它没有明确说明time_t或size_t是如何以及在何处定义和声明的。我正在使用WIN8VS2012ExpressC++。我搜索了库,发现size_t是在crtdefs.h中定义的,而不是cstddef。为什么需要size_t、time_t这样的类型?我们可以让sizeof只返回unsi

c++ - std::thread 并在 visual studio 2013 中 move

我有一个只能move的类和一个按值获取此类对象的函数。在新线程中调用函数:voidfoo(MyClassa){}intmain(){MyClassa;std::threadt(&foo,std::move(a));}我得到一个编译器错误,因为缺少MyClass的复制构造函数(我删除了他),如果我实现他,复制构造函数就会被调用。显然这是一个错误,它在gcc中编译时没有复制构造函数。有什么解决方法吗? 最佳答案 如果方法需要a的所有权,通过堆传递它,最好是在shared_ptr中:voidfoo(std::shared_ptra){}[

c++ - #pragma omp parallel num_threads 不工作

#include#include#includevoidmain(intargc,int*argv[]){#pragmaompparallelnum_threads(3){inttid=omp_get_thread_num();printf("Helloworldfromthread=%d\n",tid);if(tid==0){intnthreads=omp_get_num_threads();printf("Numberofthreads=%d\n",nthreads);}}}我正在学习OpenMP,我不明白为什么我指定了线程数3,它只执行一个线程?程序输出:Helloworldfr