-1

我正在尝试一个 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:错误:预期名称空间名称在 ';' 之前 令牌

线程类的声明

    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); }

     };
4

1 回答 1

1

您应该删除该行using namespace boost;。您的程序中似乎不需要它。

于 2012-06-23T15:24:02.373 回答