草庐IT

HAVE_PTHREAD_COND_TIMEDWAIT_MONOT

全部标签

c++ - 是否可以在没有 pthread 的情况下构建 protobuf?

在没有pthread的实时操作系统上需要使用ProtocolBuffers。我可以通过这种方式静态链接protobufg++-g-Wallexample.pb.ccexample.cc-oexample-static-lprotobuf-lpthread但是,如果没有pthread,我会收到链接错误。是否可以将protobuf配置为在没有pthread的情况下工作? 最佳答案 不是真的。参见thisUnresolved问题。有人修补了较旧的protobuf版本以使其不依赖于pthreads,请参阅here-如果你真的需要它,你可能会

C++ pthread阻塞队列死锁(我认为)

我在使用pthreads时遇到问题,我认为我遇到了死锁。我创建了一个我认为有效的阻塞队列,但在进行更多测试后,我发现如果我尝试取消阻塞在blocking_queue上的多个线程,我似乎会遇到死锁。阻塞队列很简单,看起来像这样:templateclassBlocking_Queue{public:Blocking_Queue(){pthread_mutex_init(&_lock,NULL);pthread_cond_init(&_cond,NULL);}~Blocking_Queue(){pthread_mutex_destroy(&_lock);pthread_cond_destro

c++ - Pimpl with unique_ptr : Why do I have to move definition of constructor of interface to ".cpp"?

只要我不将构造函数(B)的定义移动到标题B.h中,代码就可以工作。B.hclassImp;//imp;B();//B.cpp#include"B.h"#include"Imp.h"B::B(){}~B::B(){}Imp.hclassImp{};Main.cpp(编译我)#include"B.h"Error:deletionofpointertoincompletetypeError:useofundefinedtype'Imp'C2027我能以某种方式理解必须将析构函数移动到.cpp,因为可能会调用Imp的解构:-deletepointer-of-Imp;//somethinglik

c++ - 警告 C4251 : needs to have dll-interface to be used by clients of class

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:std::vectorneedstohavedll-interfacetobeusedbyclientsofclass'Xwarning这是我在该组中的第一篇文章。我正在创建一个DLL并在应用程序的主文件中调用它。代码编译正常,但出现以下错误:warningC4251:'PNCBaseClass::m_vAvailChannelsFromRx':class'std::vector'needstohavedll-interfacetobeusedbyclientsofclass'PNCBaseClass'3>w

C++ 11 替代 pthread_cond_timedwait

我需要让一个线程等待直到任一个超时已过,或者一个变量被另一个线程改变经过一些研究,我发现pthreads有pthread_cond_timedwait,如果我要使用pthreads,这在这种情况下可能很有用。我改用C++11线程。在不完全传递给pthreads的情况下,是否有适合我的替代方案? 最佳答案 是的,你想要std::condition_variable来自,它有一个成员函数wait_for这需要一段时间。Thecondition_variableclassisasynchronizationprimitivethatcan

c++ - vector < vector > : verify that all have equal sizes

是否有std/boost算法来验证一个vector中的所有vector是否具有相同的大小?推而广之,所有元素的属性都相同吗?在下面的示例中,我使用了我正在寻找的假设的std::all_equal:typedefstd::vectorLine;std::vectorlines;lines.push(Line(10));lines.push(Line(11));autoequalLengths=std::all_equal(lines.begin(),lines.end(),[](constLine&x){returnx.size();});(并且通过扩展:std::vectorvec;a

c++ - POSIX C 线程。 pthread_cond_t 示例。没有按预期工作

我写了一个程序,但它没有像我预期的那样工作。我有两个线程:thread触发func和anotherThread触发anotherFunc。我想做的是当cont在func中达到值10时,使用触发anotherThreadpthread_cond_wait和pthread_cond_signal。奇怪的是,如果我取消注释sleep(1)行,一切正常。我是线程的新手,我正在学习教程here如果我在他们的示例中评论sleep行,它也会中断。我的问题是如何在没有任何sleep()调用的情况下完成这项工作?如果在我的代码中func在anotherFunc之后到达pthread_mutex_lock

c++ - 'must have an argument of class or enumerated type'到底是什么意思

我有一个头文件和一个.cpp文件。我需要为我的.h文件编写函数,但在我完全完成骨架.cpp文件之前出现错误。金钱.h#ifndefMONEY_H#defineMONEY_H#include#includeusingnamespacestd;classMoney{public:Money(intdollars,intcents);Moneyoperator+(constMoney&b)const;Moneyoperator-(constMoney&b)const;Moneyoperator*(doublem)const;Moneyoperator/(doubled)const;voidp

c++ - OS X clang -pthread

在OSX中使用带有clang的pthread库的编译器/链接器要求是什么。对于GCC,我知道使用-pthread设置适当的编译器/链接器选项,但我不确定OSX是否带有clang。air:~jose$clang++-ctest.cpp-pthreadair:~jose$clang++-otest-pthreadtest.oclang:warning:argumentunusedduringcompilation:'-pthread'air:~jose$g++-ctest.cpp-pthreadair:~jose$g++-otest-pthreadtest.o

c++ - CMake 链接错误 pthread:启用多线程以使用 std::thread:不允许操作

我有一个类似的错误C++Threads,std::system_error-operationnotpermitted?我正在使用完全相同的源代码并使用进行编译g++../src/main.cpp-pthread-std=c++11工作没有任何问题。因为我想在一个更大的项目中使用线程,所以我必须在CMake中使用线程。搜索解决方案后,我发现了几个代码,例如:cmake_minimum_required(VERSION2.6)project(Test)add_definitions("-std=c++11")find_package(Threads)add_executable(main