I face a strange error with pthreads in C++, I try to run this code:
typedef struct
{
struct sockaddr_in clienAddr;
int clientLength;
string message;
}param;
pthread_t clientThread;
param sentParam ;
sentParam.clienAddr = clientAddress;
sentParam.clientLength= client_info;
sentParam.message=buffString;
cout <<"sentParam: "<<sentParam.message<<endl;
// it prints well.
int i = pthread_create(&clientThread, NULL, handleClientRequestRead,&sentParam );
cout <<"i: "<<i<<endl;
the function which be called
void* handleClientRequestRead(void* params)
{
// cout<<"params: "<< ;
string msg = (( param *)(params))->message;
}
When I try to print msg it’s empty. Any help will be appreciated
I agree with @Matteo above: