草庐IT

mutex_type

全部标签

c++ - g++ 4.7.1 编译错误 : conflicting types for ‘strsignal’

我正在尝试在Ubuntu12.0432位上从源代码编译g++4.7.1。目前我已经完全做到了:https://askubuntu.com/questions/168947/how-to-upgrade-g-to-4-7-1除了在编译g++4.7.1之前,它要求我“取消设置LIBRARY_PATH”(所以我已经这样做了)。所以编译开始了,过了一会儿我收到以下错误消息:Infileincludedfrom../.././gcc/c-lang.c:24:0:../.././gcc/system.h:499:20:erreur:conflictingtypesfor‘strsignal’/us

c++ - 如何使用 type_info 进行类型转换?

我存储了一个指向type_info对象的指针。intMyVariable=123;conststd::type_info*Datatype=&typeid(MyVariable);我如何使用它来将另一个变量类型转换为该类型?我试过这个,但它不起作用:std::cout使用类型转换的函数形式也不起作用:std::cout 最佳答案 很简单,您不能使用type_info来做到这一点。此外,在您的示例中,DataType不是类型,它是指向type_info类型对象的指针。你不能用它来转换。转换需要类型,而不是指针或对象!在C++0x中,您

C++ 错误 : object of abstract class type is not allowed: pure virtual function has no overrider

继承有问题。我不知道我做错了什么。FigureGeometry.h#ifndefFIGUREGEOMETRY#defineFIGUREGEOMETRYstaticconstfloatPI=3.14159f;classFigureGeometry{public:virtualfloatgetArea()const=0;virtualfloatgetPerimeter()const=0;};#endifCircle.h#ifndefCIRCLE#defineCIRCLE#include"FigureGeometry.h"classCircle:publicFigureGeometry{fl

c++ - <mutex> 和 <condition_variable> 的异常处理

假设没有发生未定义的行为,没有发生死锁,互斥锁被正确的线程以正确的顺序锁定和解锁正确的次数,非递归互斥锁不会被多次锁定,锁定递归互斥量不超过maximumlevelofownership,没有谓词传递给条件变量,并且只有标准库提供的时钟、时间点和持续时间与std::互斥锁和条件变量一起使用是否保证对不同类型的std::互斥量和条件变量进行操作(除了构造它们)不会抛出任何异常(尤其是类型std::system_error)?例如,在以下方法的情况下:voidMyClass::setVariable(){std::lock_guardconstguard(m_mutex);m_var=42

c++ - "boost::mpl::identity<T>::type"在这里有什么意义?

我正在检查clamp的执行情况在boost中:templateTconst&clamp(Tconst&val,typenameboost::mpl::identity::typeconst&lo,typenameboost::mpl::identity::typeconst&hi,Predp){//assert(!p(hi,lo));//Can'tassertp(lo,hi)b/ctheymightbeequalreturnp(val,lo)?lo:p(hi,val)?hi:val;}如果我查找文档,identity返回模板参数不变。Theidentitymetafunction.Re

c++ - 带有 RAII 的 std::mutex 但在后台线程中完成并释放

我有一个偶尔从GigE相机获取帧的功能,并希望它快速返回。标准流程是这样的://...camera.StartCapture();Imageimg=camera.GetNextFrame();camera.StopCapture();//在GetNextFrame()和StopCapture()之后返回数据准备就绪非常慢;因此,我想尽快返回img并生成一个后台线程来执行StopCapture()。但是,在(不太可能)再次开始获取的情况下,我想通过互斥锁来保护访问。有些地方可能会抛出异常,所以我决定使用RAII风格的锁,它会在作用域退出时释放。同时,我需要将锁转移到后台线程。像这样的东西

c++ - 是否有必要在互斥锁上调用 pthread_mutex_destroy?

我在C++程序中使用pthread_mutex_t,如下:classMutex:publicnoncopyable{public:Mutex(){pthread_mutex_init(&m_mutex,NULL);}voidacquire(){pthread_mutex_lock(&m_mutex);}voidrelease(){pthread_mutex_unlock(&m_mutex);}private:pthread_mutex_tm_mutex;};(类不可复制-http://www.boost.org/doc/libs/1_53_0/boost/noncopyable.hpp

c++ - 为什么锁定 std::mutex 不会阻塞线程

我写了下面的代码来测试我对std::mutex的理解intmain(){mutexm;m.lock();m.lock();//expecttoblockthethread}然后我得到一个system_error:deviceorresourcebusy。第二个m.lock()不是应该阻塞线程吗? 最佳答案 来自std::mutex:Acallingthreadmustnotownthemutexpriortocallinglockortry_lock.来自std::mutex::lock:Iflockiscalledbyathrea

c++ - 为什么 std::mutex 比 std::atomic 快?

我想在多线程模式下将对象放入std::vector中。所以我决定比较两种方法:一种使用std::atomic,另一种使用std::mutex。我看到第二种方法比第一种方法更快。为什么?我使用GCC4.8.1,在我的机器(8线程)上,我看到第一个解决方案需要391502微秒,第二个解决方案需要175689微秒。#include#include#include#include#include#includeintmain(intargc,char*argv[]){constsize_tsize=1000000;std::vectorfirst_result(size);std::vecto

c++ - decltype(new any_type()) 是否可能发生内存泄漏?

我正在使用valgrind检查类指针的任何内存泄漏可能性,并发现以下程序没有内存泄漏:#include#include#includeusingnamespacestd;classbase{};intmain(){unique_ptrb1=make_unique();base*b2=newbase();cout::value::value这怎么可能? 最佳答案 decltype(还有sizeof)的操作数不会被求值,所以任何副作用,包括内存分配,都不会发生。只有类型是在编译时确定的。所以这里唯一的内存分配是在make_unique和