首先,thread和pthread有什么区别。我应该在 C++ 中使用什么。
我正在尝试使用 pthread,如下所示:
//MyPatcher.h
class MyPatcher
{
public:
void createThread();
private:
void * Checkingdata(void *arg);
}
// MyPatcher.cpp
#include "MyPatcher.h"
#include <pthread.h>
using namespace std;
void MyPatcher::createThread()
{
pthread_t threadDataReading;
if(pthread_create(&threadDataReading, NULL, Checkingdata, NULL))
printf("Could not create thread\n");
if(pthread_join(threadReadingGps, NULL))
printf("Could not join thread\n");
}
void * MyPatcher::Checkingdata(void *arg)
{
return NULL;
}
但我遇到了这些问题:
./MyPatcher.cpp:71:73: error: argument of type 'void* (SampleApp::MyPatcher::)(void*)' does not match 'void* (*)(void*)'
我怎么解决这个问题?
// 然后我也尝试使用线程:
//MyPatcher.h
class MyPatcher
{
public:
void createThread();
private:
void Checkingdata();
}
// MyPatcher.cpp
#include "MyPatcher.h"
#include <thread>
using namespace std;
void MyPatcher::createThread()
{
pthread_t threadDataReading(Checkingdata);
threadDataReading.join();
}
void MyPatcher::Checkingdata()
{
}
但我遇到了这个问题:错误:没有匹配函数调用'std::thread::thread()'