// I wrote following code of pthread, but it doesnt compile ? How to use pthread in c++ ?
#include <iostream>
#include <pthread.h>
using namespace std;
class Emp
{
public:
int eno;
int salary;
public:
Emp()
{
eno = 10;
salary = 90000;
}
void show()
{
cout << "\n Emp No : " << this->eno;
cout << "\n Emp Salary : " << this->salary;
}
};
void *printData( void * obj )
{
//((Emp *)obj)->show();
cout << "\n Emp No : " << ((Emp *)obj)->eno;
cout << "\n Emp Salary : " << ((Emp *)obj)->salary;
pthread_exit( NULL );
}
int main(int argc, char *argv[])
{
pthread_t myThread;
Emp e1;
int rc = pthread_create( &myThread, NULL, &printData, &e1 ); // thread pointer, attribute, functionPointer( start_router ), agrument
if ( rc != 0 )
{
cout << "Error:unable to create thread," << rc << endl;
exit(-1);
}
}
// Please tell me what is wrong with this code ?
// Please tell me what is wrong with this code ? // Please tell me what is wrong with this code ? // Please tell me what is wrong with this code ? // Please tell me what is wrong with this code ?
Aucun commentaire:
Enregistrer un commentaire