This Thread class that i inherit from it and implement function run in child classes
---
IThread::IThread()
{
m_tid = 0;
m_running = -1;
m_detached = -1;
}
IThread::~IThread()
{
if (m_running == 1 && m_detached == 0) {
pthread_detach(m_tid);
}
if (m_running == 1) {
printf("\n from thread %lu \n",m_tid);
pthread_cancel(m_tid);
}
}
int IThread::start()
{
int result = pthread_create(&m_tid, NULL, runThread, this);
if (result == 0) {
m_running = 1;
}
return result;
}
int IThread::join()
{
int result = -1;
if (m_running == 1) {
result = pthread_join(m_tid, NULL);
if (result == 0) {
m_detached = 1;
}
}
return result;
}
int IThread::detach()
{
int result = -1;
if (m_running == 1 && m_detached == 0) {
result = pthread_detach(m_tid);
if (result == 0) {
m_detached = 1;
}
}
return result;
}
pthread_t IThread::self() {
return m_tid;
}
void* IThread::run()
{
printf("DFDF");
return 0;
}
and this handleRequest class inherit from Ithread and i call this function in its run
void HandleRequest::AcceptConnection()
{
struct sockaddr_in client;
unsigned int len;int s;
;
CircularResponse * r;
len = sizeof(client);
while(true)
{
s = accept(Socket,(struct sockaddr*)&client,&len);
if( s > -1)
{
r = new CircularResponse();
printf("\n other client port %i\n",client.sin_port);
HandleResponse * re = new HandleResponse();
re->;set_Client(s);
r->addClient(re);
r->start();
printf("\n fn\n");
}
else
{
printf("\n listing for connect \n");
}
}
}
and this function thread that run for every response
while(true)
{
if(!qclient->empty()&&!wait)
{
current = qclient->front();
current->start();
qclient->pop();
h = current->check_connect();
if(h==-1)
{
current->detach();
delete current;
printf("\n running %i \n",current->m_running);
pthread_kill(current->m_tid,SIGKILL);
printf("running %i \n",current->m_running);
printf("\n here I kill thread %lu \n",current->self());
break;
}
qclient->push(current);
current->join();
printf("\n client connected %i \n",(int)qclient->size());
}
the problem if i kill Thread read if client close session the all thread kill and app stop