草庐IT

five9_calls

全部标签

c++ - std::call_once 是否可重入且线程安全?

std::call_once是线程安全的,但它也是可重入的吗?我使用VS2012(调试和发布)进行的测试表明,从单个线程递归调用std::call_once是可以的,但如果在单独的线程上进行调用,则会导致死锁。这是std::call_once的已知限制吗?#include"stdafx.h"#include#include#includevoidFoo(){std::cout似乎std:call_once正在锁定一个静态互斥锁,该互斥锁在函数退出之前不会解锁。在单线程的情况下它可以工作,因为在第二次调用时该线程已经拥有了锁。在线程版本上,它将阻塞直到第一个调用退出。我还注意到,如果将F

c++ - 如何使用 TBB 多线程 "tail call"递归

我正在尝试使用tbb对现有的递归算法进行多线程处理。单线程版本使用尾调用递归,从结构上看是这样的:voidmy_func(){my_recusive_func(0);}booldoSomeWork(inti,int&a,int&b,int&c){//dosomework}voidmy_recusive_func(inti){inta,b,c;boolnotDone=doSomeWork(i,a,b,c);if(notDone){my_recusive_func(a);my_recusive_func(b);my_recusive_func(c);}}我是一个tbb新手,所以我第一次尝试

c++ - 错误 C4996 : 'std::_Copy_impl' : Function call with parameters that may be unsafe

我知道这个问题在SO中被问过很多次,但这是与其他问题的不同。CompilerError:FunctioncallwithparametersthatmaybeunsafeVisualStudioWarningC4996xutility(2227):warningC4996:'std::_Copy_impl'失败的代码片段DWORDdwNumberOfNames=pExportDirectory->NumberOfNames;LPDWORDdwNames=(LPDWORD)((LPBYTE)hDLL+pExportDirectory->AddressOfNames);std::vecto

c++ - 铛++ : error: call to 'partition' is ambiguous

#include#includetemplateBidirectionalIteratorpartition(BidirectionalIteratorfirst,BidirectionalIteratorlast,UnaryPredicatepred){while(first!=last){while(pred(*first)){++first;if(first==last)returnfirst;}do{--last;if(first==last)returnfirst;}while(!pred(*last));std::swap(*first,*last);++first;}re

C++ 继承 : Calling virtual method when it has been overridden

我正在尝试构建一个可以在单独的线程中运行(即执行它的run()函数)的service对象。这是服务对象#include#include#include#includeclassservice:publicboost::noncopyable{public:service():stop_(false),started_(false){}virtual~service(){stop();if(thread_.joinable()){thread_.join();}}virtualvoidstop(){stop_=true;}virtualvoidstart(){if(started_.lo

c++ - std::call_once,应该什么时候用?

std::call_oncefunction,在C++11中引入,确保可调用对象以线程安全的方式被恰好调用一次。因为这可以通过其他方式实现-什么时候应该使用std::call_once?它旨在解决什么类型的问题?请举例说明。 最佳答案 示例:我将它用于libcURL从网站检索http(s)数据。在libcURL中,您必须执行one-timeglobalinitialization在你能够使用图书馆之前。鉴于初始化是不是线程安全的,但从网站请求数据是线程安全的,我使用call_once只调用我的初始化一次,无论在什么线程中以及是否它被

c++ - 调试断言失败表达式 : _pFirstBlock == pHead using OpenCV and C++ trying to call SurfFeatureDetector

我在使用OpenCV的C++中有这个函数:vectortest(Matimg){intminHessian=400;SurfFeatureDetectordetector(minHessian);vectorvKeypoints;detector.detect(img,vKeypoints);returnvKeypoints;}当我在主方法中调用此函数时,一切正常。intmain(int,char**argv){//pathtoaimage-filechar*input="image.jpg";//readimageintoMatimgMatimg=imread(input,CV_LO

c# - C++ Interop : How do I call a C# class from native C++, 类是非静态的吗?

我有一个用nativeC++编写的大型应用程序。我还有一个C#类需要调用。如果C#类是静态的,那将是微不足道的(网络上有很多示例)-只需编写混合的C++/CLI包装器,导出接口(interface),即可完成。但是,C#类是非静态的,并且不能更改为静态的,因为它有一个接口(interface)(如果您试图将C#类设为静态,编译器将生成错误)。以前有没有人遇到过这个问题-如何将非静态C#类导出到nativeC++?更新2010-11-09最终解决方案:尝试使用COM,效果很好,但不支持结构。所以,我选择了C++/CLI包装器,因为我绝对需要能够在C++和C#之间传递结构。我根据此处的代码

c++ - 如何影响_calling_函数的值返回?

我希望能够强制执行“双重返回”,即拥有一个强制从其调用函数返回的函数(是的,我知道并不总是真正的调用函数等)显然我希望能够通过操纵堆栈来做到这一点,并且我认为至少以某种不可移植的机器语言方式是可能的。问题是这是否可以相对干净和便携地完成。给个具体的代码来填,我要写函数voidfoo(intx){/*magic*/}使得下面的函数intbar(intx){foo(x);/*longcomputationhere*/return0;}返回,比方说,1;并且不执行长计算。假设foo()可以假设它只被带有bar签名的函数调用,即int(int)(因此明确知道它的调用者返回类型是什么).注意事项

C++ 继承 : Calling Base Class Constructor In Header

假设类Child是类Parent的派生类。在一个五文件程序中,我如何在Child.h中指定我想调用Parent的构造函数?我认为header中的以下内容不合法:Child(intParam,intParamTwo):Parent(Param);在这种情况下,Child.cpp的构造函数语法应该是什么样的? 最佳答案 在Child.h中,您只需声明:Child(intParam,intParamTwo);在Child.cpp中,您将拥有:Child::Child(intParam,intParamTwo):Parent(Param){