pthread_t on mac os x is NULL

pthread_t on mac os x is NULL

本文关键字:is NULL os mac on pthread      更新时间:2023-10-16

我在AIX/H-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上执行相同的代码,有人知道为什么会发生这种情况。

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

您不应该检查m_thread != NULL,这毫无意义。去掉那张支票,它应该能正常工作。

在进行测试时,您还没有初始化m_thread——它的值是不确定的。