Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the base class that parent of any class that work as thread
but PTHDB_CALLBACK (callback failed) signal is occur when i run 100 thread per second
C++
#include"Thread.h"
#include<signal.h>
friend  void* runThread(void*arg){return  ((IThread*)arg)->run();}; //implemented in .h file
IThread::IThread()
{
	   m_tid = 0;
	   m_running = -1;
	  m_detached = 0;
	//  signal(SIGPIPE,SIG_IGN);

}
/*static void*  runThread(void* arg)
{
}*/

IThread::~IThread()
{
	 if (m_running == 1 && m_detached == 0) {
	       printf("\n deaached from thread %lu \n",m_tid);
	        pthread_detach(m_tid);
	    }
	    if (m_running == 1) {
	    	printf("\n cancel from thread %lu \n",m_tid);
	        pthread_cancel(m_tid);
			 pthread_attr_destroy(&attr);  
	    }
}

int IThread::start()
{
    pthread_attr_t attr;
     int g = pthread_attr_init(&attr);
     if(g!=0)
    	 printf("\nfail attr\n");
    pthread_attr_setstacksize(&attr,2000*1000);
	int res = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    int result = pthread_create(&m_tid, &attr, 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("Empty thread");
	return 0;
}
Posted
Updated 10-Dec-14 13:35pm
v2

1 solution

you need a faster pc with more RAM and more speedier CPU. Or some programmer should debug the code...
 
Share this answer
 
Comments
Mahmoud_Gamal 16-Dec-14 6:57am    
i work on AIX ibm 7.1 server with with 16 core every core 3.7 GH and ram 16 G ram
so i think this is no probelm and it it background service so difficult to debug
i use instead show message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900