Oder nochmal in C++11
Code:
#include <iostream>
#include <thread>
using namespace std;
typedef struct {
pthread_t tid;
char* name;
float p;
float i;
float d;
} PID_t;
class TestClass
{
public:
TestClass() {}
~TestClass() {}
void Start(PID_t *p)
{
t = new thread(&this->MyTask, p);
}
void Stop()
{
t->join();
}
private:
static void MyTask(PID_t *p)
{
cout << "PID: " << p->tid << endl;
cout << "Name: " << p->name << endl;
}
thread *t;
};
int main()
{
cout << "Start" << endl;
PID_t pp[3] = { {0, (char*)"MyName1", 5, 6, 7},
{1, (char*)"MyName2", 5, 6, 7},
{2, (char*)"MyName3", 5, 6, 7}};
TestClass tc1;
TestClass tc2;
TestClass tc3;
tc1.Start(&pp[0]);
tc2.Start(&pp[1]);
tc3.Start(&pp[2]);
//...
tc1.Stop();
tc2.Stop();
tc3.Stop();
return 0;
}
Lesezeichen