草庐IT

index-async

全部标签

c++ - 为什么即使使用指定的 std::launch::async 标志,std::async 也会同步调用该函数

我传递给std::async的函数打印当前线程ID。尽管使用std::launch::async标志调用,它仍打印相同的theadid。这意味着它同步调用该函数。为什么?voidPrintThreadId(){std::cout输出是:2093620936209362093620936环境:VS2015,W7。提前致谢! 最佳答案 您实际上通过等待每个调用来序列化调用,因此可以重复使用同一个线程而不会破坏std::future由不同于调用者线程当以下代码显示与其他代码相同的CallerThreadId时,请唤醒我们:voidPrin

c++ - 将 std::type_index 作为模板参数传递给函数模板

考虑以下代码(工作正常):namespacefruit{structapple{};}namespacelanguage{structenglish{};}typedefstd::pairmyPairType;std::unordered_mapmyMap={{"paul",{"likes",std::type_index(typeid(fruit::apple))}},{"jonas",{"likes",std::type_index(typeid(language::english))}}};现在我有以下功能模板:templatevoidGenerateProfile(void*d

c++ - boost async_write 问题

我将展示一些代码;voidwh(constboost::system::error_code&ec,std::size_tbytes_transferred){std::cout当我使用该代码时出现内存泄漏,我发现一些代码(如minicom_client教程)甚至从该代码中变得复杂,而且我在minicom_client上出现内存泄漏。如果我使用boost::asio::write(pSerial,boost::asio::buffer("A",1));代替async_write效果很好,你能解释一下那里发生了什么吗,非常感谢...... 最佳答案

c++ - std::async 不并行化任务

在此代码段中使用C++11std::async:intfoo(){::sleep(2);return123;}intmain(){futurer1(async(foo));intr2=foo();cout它产生正确的结果,但连续运行两个foo(整个应用程序运行4秒)。编译为:g++-std=gnu++11-O2foo.cc-lpthread(Ubuntu12.1064位,gcc4.7.2) 最佳答案 您可能需要添加launchpolicystd::launch::async的:std::async(std::launch::asyn

c++ - std::async 超时

有没有办法在std::async方法中实现超时,所以如果线程在指定的时间内没有完成,我希望这个调用超时并完成。我该如何实现此功能。 最佳答案 没有(标准的)方法可以进入线程并杀死它,无论如何这通常不是一个好主意。更简洁的选择是将开始时间和最长持续时间传递给函数,然后(可能随着计算的进行多次)检查当前时间减去开始时间是否太长。我会做这样的事情:#includetemplateclasstimeout{public:typedefClockclock_type;typedeftypenameclock_type::time_pointt

c++ - std::async 在指定 launch::async 时不执行

也许我错过了C++11中新std::async的正确用法,但是这个声明(在cppreference.com结束):Iftheasyncflagisset(i.e.policy&std::launch::async!=0),thenasyncexecutesthefunctionfonaseparatethreadofexecutionasifspawnedbystd::thread(f,args...),exceptthatifthefunctionfreturnsavalueorthrowsanexception,itisstoredinthesharedstateaccessibl

c++ - 为什么 boost.geometry.index.rtree 比 superliminal.RTree 慢

我测试了boost.geometry.index.rtree(boost1.59www.boost.org)和superliminal.RTree(http://superliminal.com/sources/sources.htm#C_Code)。令我惊讶的是,superliminal.RTree比boost.geometry.index.rtree更快。环境设置将相同的空间索引数据添加到superliminal.RTree和boost.geometry.index.rtree对象。测试相同的空间索引查询100次并获得消耗的时间。GCC版本是“gccversion4.4.62011

c++ - 使用 std::async 调用模板函数的正确方法是什么

我正在尝试了解std::async的用途。我在下面编写了模板函数来将所有条目累积到一个整数数组中。template::value>::type>Tparallel_sum(T(&arr)[N],size_tstart=0,size_tend=N-1){if(end-start,arr,start,mid);autores2=parallel_sum(arr,mid+1,end);returnres2+res1.get();}}当我在main中调用上面的函数时,出现以下编译错误(以及更多错误):errorC2672:'std::async':nomatchingoverloadedfun

c++ - CDT : "Setting up indexer" 期间发生内部错误

我将Eclipse与CDT结合使用来构建C++代码。加载我的工作区后,我收到以下消息:Aninternalerroroccurredduring:"Settingupindexer".这是日志:eclipse.buildId=I20110613-1736java.version=1.6.0_24java.vendor=SunMicrosystemsInc.BootLoaderconstants:OS=linux,ARCH=x86,WS=gtk,NL=en_USCommand-linearguments:-oslinux-wsgtk-archx86!ENTRYorg.eclipse.co

成功解决使用git clone下载失败的问题: fatal: 过早的文件结束符(EOF) fatal: index-pack 失败

一.使用http可能出现的问题和解决1.问题描述~$gitclonehttps://github.com/oKermorgant/ecn_baxter_vs.git正克隆到'ecn_baxter_vs'...remote:Enumeratingobjects:13,done.remote:Countingobjects:100%(13/13),done.remote:Compressingobjects:100%(10/10),done.error:RPCfailed;curl56GnuTLSrecverror(-54):Errorinthepullfunction.fatal:Theremo