草庐IT

c++ - Visual Studio 2010 中的 boost::thread 编译错误

我在很长一段时间内第一次尝试使用boost,当我包含boost/thread.hppheader时,我在boost本身内部遇到编译错误:c:\myproj\boost_1_46_0\boost\thread\win32\thread_heap_alloc.hpp(97):errorC2061:syntaxerror:identifier'heap_memoryc:\myproj\boost_1_46_0\boost\thread\detail\thread.hpp(134):seereferencetofunctiontemplateinstantiation'T*boost::det

c++ - 链接 boost::thread

我正在尝试使用boost库学习一些东西,但是当我尝试编译包含boost::threads的东西时遇到了问题。我在链接过程中遇到错误,消息如下:/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld:cannotfind-lboost-thread但这很奇怪,因为只有当我用普通用户编译时才会发生这种情况,使用root我可以毫无问题地编译。提前致谢。 最佳答案 包含#include其他链接器标志-lboost_system-lboost_

c++ - debian 和 std::thread c++ 的即时段错误

遇到这个问题-在标题中..我有这个代码:#include#includevoidmy_thread_func(){std::cout摘自网络某处。编译器选项-pthread-std=gnu++0x(也试过-std=c++0x)而且我有段错误。一切都在vmBox上的Debian上。我之前已经启动了其他代码,并且它们有效。突然间,我在所有工作应用程序中使用std::thread的线程上出现段错误。编辑:这是来自gdb:(gdb)where#00x00000000in??()#10x08048dc9inthread(this=0xbffff3fc,__f=0x8048b9f)at/usr/i

c++ - OpenMP Mac OSX Lion c++ 链接器错误 Undefined symbols for architecture x86_64 : "_omp_get_thread_num"

我在互联网上的任何地方都找不到这个问题。所以我的链接器错误是:Undefinedsymbolsforarchitecturex86_64:"_omp_get_thread_num()"这是我的代码:intnthreads;inttid;#pragmaompparallelprivate(tid){tid=omp_get_thread_num();if(tid==0){nthreads=omp_get_num_threads();printf("numberofthreads:%d\n",nthreads);}} 最佳答案 看起来你忘

c++ - boost::scoped_lock 不适用于局部静态变量?

我制作了以下示例程序来使用boost线程:#pragmaonce#include"boost\thread\mutex.hpp"#includeclassThreadWorker{public:ThreadWorker(){}virtual~ThreadWorker(){}staticvoidFirstCount(intthreadId){boost::mutex::scoped_lock(mutex_);staticinti=0;for(i=1;i主类://ThreadTest.cpp#include"stdafx.h"#include"boost\thread\thread.hpp

c++ - 为什么这个程序抛出 'std::system_error' ?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whydoesthissimplestd::threadexamplenotwork?代码:#include#includevoidf(){std::cout问题:$g++-othread_testthread_test.cpp-std=c++0x$./thread_testterminatecalledafterthrowinganinstanceof'std::system_error'what():OperationnotpermittedAbortado“Abortado”在我的语言环境中表示“中止”

c++ - 在 main() 的线程中调用对象成员函数

这个问题在这里已经有了答案:Startthreadwithmemberfunction(5个答案)关闭8年前。我发现了很多关于在类中创建新线程的信息(Passingmemberfunctionstostd::thread)但是否有可能以某种方式执行以下操作:#include#includeusingnamespacestd;classmyClass{public:myClass(){myInt=2;};voidmyFun(){++myInt;}intret_myInt(){returnmyInt;}private:intmyInt;};intmain(void){myClassmyOb

c++ - 错误:使用已删除的函数'test::test (const test&) C++ 结合 vector

我有一个我不明白的问题。我有一个生成线程的类。一切都好。我制作了一个新对象-一切正常。如果我将这些存储在一个vector中以迭代我的代码将无法编译。我使用g++4.9i686。我制作了以下简短程序,它完全模拟了问题,因为真实代码相当广泛。如果有人可以澄清或给我一个对我的宠物项目非常有用的解决方案,因为我坚持这个。代码如下:#include#include#include#includeclasstest{public:test();voidsetstring(std::strings);~test(){}voidrunThread(){m_thread=std::thread(&tes

C++线程执行完后还是 `joinable()`?

我有以下功能:voidthreadProc(){for(inti=0;i我正在按以下方式使用它:intmain(){try{std::threadt1(threadProc);t1.join();std::threadt2(threadProc);HANDLEhandle=t2.native_handle();WaitForSingleObject(handle,INFINITE);std::this_thread::sleep_for(std::chrono::milliseconds(5000));std::cout这是输出:thread#21300sayshithread#213

C++:具有 `std::lock_guard` 的互斥量是否足以同步两个 `std::thread`?

我的问题是基于下面的C++代码示例#include#include#include#includeclassClassUtility{public:ClassUtility(){}~ClassUtility(){}voiddo_something(){std::coutlock(g_mutex);std::coutlock(g_mutex);std::cout如果需要,这更像是一个问题,目的是让我的理解更清楚,并获取std::condition_variable的示例用法。我有2个C++std::thread,它们在main方法中启动。它是osx上的控制台应用程序。所以使用clang编