Re: simple pthread
"cerr" <ron.eggler@gmail.com> ha scritto nel messaggio
news:d7dba757-ed45-4a21-b086-e4b62b363e1d@u6g2000prc.googlegroups.com...
i have now something like this:
int MyThread::StartMe(void)
{
// starting thread
pthread_create(&ThreadA, NULL, &PrintMsg, NULL);
}
//-------------------------------------------------------------
void PrintMsg(void)
{
//thread function
while (1) {
pthread_mutex_lock( &mutex1 );
count++;
pthread_mutex_unlock( &mutex1 );
cout << "I Incremented count: " << count << endl;
}
}
but I get following:
$ g++ -pthread -o example example.cpp
example.cpp: In member function ?int MyThread::StartMe()?:
example.cpp:66:49: error: invalid conversion from ?void (*)()? to
?void* (*)(void*)?
example.cpp:66:49: error: initializing argument 3 of ?int
pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*),
void*)?
How do I gwet this compiled? How do I pass a void argument?
Thank you!
-------------------
i modify somthing; in printmsg i impose count<100000
unsigned count=0;
void* PrintMsg(void* unused)
{(void) unused;
//thread function
while (1)
{ pthread_mutex_lock( &mutex1 );
count++;
pthread_mutex_unlock( &mutex1 );
cout << "I Incremented count: " << count << endl;
if(count>=100000) break;
}
return 0;
}
void MyThread::StartMe(void)
{// starting thread
pthread_create(&ThreadA, 0, &PrintMsg, 0);
}