/*
* want multi-threading in c++ code, tried boost, working perfectly.
* But want to use pthread with c++, just for fun and it works

* Following is the sample code:
*/
#include <iostream>
#include <string>
#include <cstdio>
extern "C"{
#include <pthread.h>
#include <errno.h>
}
using namespace std;
class Tester
{
private:
int value;
public:
Tester() {}
~Tester() {}
void setData(int i) {value = i;}
int getData() {return value;}
void printData()
{
int i;
for (i=value; i < (value + 10); i++) cout << "value: " << i << "\n";
}
};
void *runner(void *ptr)
{
Tester *test = static_cast<Tester*>(ptr);
test->printData();
return NULL;
}
int main(int argc, char *argv[])
{
Tester test;
pthread_t th;
test.setData(6);
if (pthread_create(&th, NULL, runner, static_cast<void*>(&test)) != 0)
{
perror("pthread_create()");
return -1;
}
pthread_join(th, NULL);
return 0;
}