[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: thread memory leak
From: |
David Sugar |
Subject: |
Re: thread memory leak |
Date: |
Sun, 2 Feb 2003 20:25:56 -0500 |
User-agent: |
KMail/1.4.3 |
Since thread a is a detached thread, you cannot "join" or delete it from
another thread. It must delete itself as it exits through it's final.
On Sunday 02 February 2003 19:03, address@hidden wrote:
> Hello,
>
> I get 3 Memory leaks when I run this example(BorlandC/Win32/latest CVS
> version)
> leaks:
> 2x myThread each 32 byte
> 1x MainThread 32 byte
>
> Can someone pls help me and point what is wrong?
>
> Thanks,
> Adib.
>
> //-------------------------------------------------------------------------
>-- class myThread : public Thread
> {
> char m_c;
> public:
> myThread(char c){m_c=c;}
> void run(void)
> {
> setCancel(Thread::cancelImmediate);
> while(1)
> {
> std::cout << m_c;
> sleep(500);
> }
> }
> };
>
> #pragma argsused
> int main(int argc, char* argv[])
> {
> myThread *a=new myThread('a'), *b=new myThread('b');
> a->detach();
> b->start();
> char z=0;
> while(1)
> {
> z=getch();
> if(z=='a') a->suspend();
> else if(z=='b') b->suspend();
> else if(z=='A') a->resume();
> else if(z=='B') b->resume();
> printf("zei=%c", z);
> if(z==0x1b) break;
> }
> delete a;
> delete b;
> }
>
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp