如何在linux c++中实现posix线程。保存为“.c并使用c编译器运行的smme程序是可以的。但是在c++中它给出了错误..
我认为我在编译时犯了错误,是否包含任何标签,例如 c++ 的“-lpthread”
有人可以发送一个有效的代码...?
其实这是我的代码
int cooperbussman :: startlistenthread()
{
if(pthread_create(&m_thread,0,&packetreadertask,0)<0)
{
cout<<"Unable to create the thread Startlistenthread\n";
return -1;
}
return 1;
我得到的错误是
cooperbussman.cpp:在成员函数âint cooperbussman::startlistenthread()â中: cooperbussman.cpp:76: 错误:从 'void* (*)()' 到 'void* (*)(void*)' 的无效转换 cooperbussman.cpp:76: 错误: 初始化参数 3 âint pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)â