G
Gary Wessle
Hi
I am trying to understand how pthread is used, so I make the scenario
below, I could not understand the erros by reading the man
pthread_create.
//**************** code start ****************
#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
using namespace std;
void print_a(){
for ( int i=0; i<10; i++)
cout << "a";
}
void print_b(){
for ( int i=0; i<10; i++)
cout << "b";
}
int main(){
pthread_t thr_a_ID;
pthread_create ( &thr_a_ID, NULL, print_a, NULL );
pthread_t* thr_b_ID;
pthread_create ( &thr_b_ID, NULL, print_b, NULL );
}
//**************** code end ****************
**************** error ****************
main.cpp:23: error: invalid conversion from ¡Ævoid (*)()¡Ç to ¡Ævoid*
(*)(void*)¡Ç
main.cpp:23: error: initializing argument 3 of ¡Æint
pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*),
void*)¡Ç
main.cpp:26: error: cannot convert ¡Æpthread_t**¡Ç to ¡Æpthread_t*¡Ç
for argument ¡Æ1¡Ç to ¡Æint pthread_create(pthread_t*, const
pthread_attr_t*, void* (*)(void*), void*)¡Ç
make: *** [main.o] Error 1
****************************************************************
I tried to change argument 3 of pthread_create to &print_a.
thanks
I am trying to understand how pthread is used, so I make the scenario
below, I could not understand the erros by reading the man
pthread_create.
//**************** code start ****************
#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
using namespace std;
void print_a(){
for ( int i=0; i<10; i++)
cout << "a";
}
void print_b(){
for ( int i=0; i<10; i++)
cout << "b";
}
int main(){
pthread_t thr_a_ID;
pthread_create ( &thr_a_ID, NULL, print_a, NULL );
pthread_t* thr_b_ID;
pthread_create ( &thr_b_ID, NULL, print_b, NULL );
}
//**************** code end ****************
**************** error ****************
main.cpp:23: error: invalid conversion from ¡Ævoid (*)()¡Ç to ¡Ævoid*
(*)(void*)¡Ç
main.cpp:23: error: initializing argument 3 of ¡Æint
pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*),
void*)¡Ç
main.cpp:26: error: cannot convert ¡Æpthread_t**¡Ç to ¡Æpthread_t*¡Ç
for argument ¡Æ1¡Ç to ¡Æint pthread_create(pthread_t*, const
pthread_attr_t*, void* (*)(void*), void*)¡Ç
make: *** [main.o] Error 1
****************************************************************
I tried to change argument 3 of pthread_create to &print_a.
thanks