未定义的命名空间'boost'

时间:2012-06-23 15:21:46

标签: c++ multithreading

我正在尝试一个C ++小线程程序,但有错误我无法处理它。

守则

#include "Threads.h"
#include "Interthread.h"


void* task1(void *arg) {
// do stuff
}

void task2() {
// do stuff
}

int main (int argc, char ** argv) {
using namespace boost;
Thread thread_1;
thread_1.start (task1,NULL);
// Thread thread_2 = thread(task2);

// do other stuff
//thread_2.join();
thread_1.join ();
return 0;

错误

Test.cpp:15:21:错误:'boost'不是命名空间名称 Test.cpp:15:26:错误:';'标记

之前的预期命名空间名称

Thread Class的声明

    class Thread {

    private:

    pthread_t mThread;
    pthread_attr_t mAttrib;
    // FIXME -- Can this be reduced now?
    size_t mStackSize;


    public:

    /** Create a thread in a non-running state. */
    Thread(size_t wStackSize = (65536*4)):mThread((pthread_t)0) {mStackSize=wStackSize;}

    /**
            Destroy the Thread.
            It should be stopped and joined.
    */
    ~Thread() { int s = pthread_attr_destroy(&mAttrib); assert(s==0); }


    /** Start the thread on a task. */
    void start(void *(*task)(void*), void *arg);

    /** Join a thread that will stop on its own. */
    void join() { pthread_join(mThread,NULL); }

     };

1 个答案:

答案 0 :(得分:1)

您应该删除第using namespace boost;行。您的计划似乎不需要它。