Cha*_*hra 2 c++ multithreading posix
如何在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;
Run Code Online (Sandbox Code Playgroud)
而我得到的错误是
cooperbussman.cpp: In member function âint cooperbussman::startlistenthread()â: cooperbussman.cpp:76: error: invalid conversion from âvoid* (*)()â to âvoid* (*)(void*)â cooperbussman.cpp:76: error: initializing argument 3 of âint pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)â
您的packetreadertask
函数必须是一个以单个void *
为参数的函数.这是重要的错误消息:
cooperbussman.cpp:76: error: invalid conversion from âvoid* (*)()â to âvoid* (*)(void*)â
您的函数声明如下:
void *packetreadertask();
Run Code Online (Sandbox Code Playgroud)
它必须在哪里:
void *packetreadertask(void *);
Run Code Online (Sandbox Code Playgroud)