Skip to content

pthread_create  #19

@wwd2018

Description

@wwd2018

void TCPServer::accepted()
{
socklen_t sosize = sizeof(clientAddress);
descript_socket so = new descript_socket;
so->socket = accept(sockfd,(struct sockaddr
)&clientAddress,&sosize);
so->id = num_client;
so->ip = inet_ntoa(clientAddress.sin_addr);
newsockfd.push_back( so );
cerr << "accept client[ id:" << newsockfd[num_client]->id <<
" ip:" << newsockfd[num_client]->ip <<
" handle:" << newsockfd[num_client]->socket << " ]" << endl;

//pthread_create(&serverThread[num_client], NULL, &Task, (void *)newsockfd[num_client]);
pthread_create(&serverThread[num_client], NULL, Task, (void *)newsockfd[num_client]);

isonline=true;
num_client++;

}

why use "&Task" ? I think should use “Task” !! both ways of writing code can work, I can't understand the reason of them.

@kashimAstro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions