mac os x上的pthread_t为NULL

时间:2012-03-01 21:45:40

标签: c++ multithreading sockets

我在AIX / HP-UX / LINUX上使用此代码,但是当我尝试在Mac OS x上运行它时它不能正常工作:

pthread_t m_thread;
                int merror;//thread return
cout << "init" << endl;
                if (m_thread != NULL){
 cout << "running" << endl;
 merror= pthread_create(&m_thread, NULL, _exec, NULL);//initialize thread
}

在linux上创建pthread并在屏幕上显示正在运行的消息。 但是在Mac OS x上,m_thread返回null,因此o无法在MAC OS X上执行相同的代码,有人知道它为什么会发生。

编译代码:g ++ -g -o sclient sclient.cpp socket.cpp -pthread -lpthread -thread

2 个答案:

答案 0 :(得分:3)

你不应该检查m_thread != NULL,这没有任何意义。删除该检查,它应该工作正常。

答案 1 :(得分:0)

您在进行测试时尚未初始化m_thread - 它的值是不确定的。

相关问题