Hi All,
Not sure where to put pthread_attr_init and setdetachstate. Should they be called once for many threads as below or each instance of a new thread:
Code:
res = pthread_attr_init(&thread_attr);
if (res != 0)
{
syslog(LOG_ERR,":Error - Server thread error: %s",strerror(res));
return 5;
}
res = pthread_attr_setdetachstate(&thread_attr,1);//PTHREAD_CREATE_DETACHED);
if (res != 0)
{
syslog(LOG_ERR,":Error - Server thread error: %s",strerror(res));
return 6;
}
for(;;)
{
cli_size = sizeof(cli);
client = accept(s, (struct sockaddr *)&cli, &cli_size);
if (client == -1)
{
syslog(LOG_ERR,":Error - Server thread error: %s",strerror(client));
return 7;
}
if(cob_silent)
printf("Got client from %s\n", inet_ntoa(cli.sin_addr));
res = pthread_create(&tid,&thread_attr,HandleRequest,&client);
if (res != 0)
{
syslog(LOG_ERR,":Error - Server thread error: %s",strerror(res));
return 8;
}
pthread_detach(tid);
}
Thanks for your help,
rotis23