pthread从另一个类返回值

时间:2014-04-03 12:51:07

标签: c++ pthreads

我想从另一个类中调用一个线程(在类中声明)。该函数必须返回一个值,但它不起作用。我正在使用POSIX线程。 如果您知道其他方式,请告诉我提前致谢 - 以下是代码:

//------Class 1 - Declare Thread----------
//------ Header File ------

pthread_t m_thread1;

list<myType*> threadtest();
static void* threadFunction(void *obj);

//------ Source File ------

list<myType*> Class1::threadtest() {
    pthread_create(&m_thread1, NULL, &Class1::threadFunction, this);
    pthread_join(m_thread1, NULL);
}
void* Class1::threadFunction(void *obj) {
    reinterpret_cast<Class1 *> (obj)->threadtest();  //threadtest returns a
                                                     //list<myType*>
    return NULL;
}


//----- Class 2 Source File - Use of thread -------- 
...
mylist = class1object->threadtest();
...

注意:我成功使用了类似于上面的东西,但是线程函数没有返回任何东西

0 个答案:

没有答案
相关问题