我使用AIX/HP-UX/LINUX这个代码,但是当我尝试在Mac OS X上运行它,它不工作得好:的pthread_t在Mac OS X是NULL
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,所以不能在MAC OS X上执行相同的代码,有人知道它为什么会发生。
的编译代码:G ++ -g -o sclient sclient.cpp socket.cpp -pthread -lpthread -thread
讨厌这么说,但是你的代码对我没有任何NULL返回值(MacOS 10.7.3) – 2012-03-01 21:56:16
你是否收到错误?你的代码在'pthread_create'返回后做了什么? (如果你结束这个过程,线程可能没有机会运行。) – 2012-03-01 22:03:52
解决了,我不知道为什么在Linux上测试返回它的好,所以我删除了测试。 – Lefsler 2012-03-02 00:16:13