public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* RE: cleaning of memory in pthread_create
@ 2002-09-10  5:28 Bossom, John
  0 siblings, 0 replies; 3+ messages in thread
From: Bossom, John @ 2002-09-10  5:28 UTC (permalink / raw)
  To: 'rpj@ise.canberra.edu.au', pankaj bathwal; +Cc: pthreads-win32

Not calling pthread_join on an undetached thread will
leak resources on ALL platforms.

John.

-----Original Message-----
From: Ross Johnson [mailto:rpj@ise.canberra.edu.au]
Sent: September 10, 2002 8:14 AM
To: pankaj bathwal
Cc: pthreads-win32@sources.redhat.com
Subject: Re: cleaning of memory in pthread_create


pankaj bathwal wrote:
> Hi,
> This is regarding freeing of resource and cleaning of
> memory allocated when "pthread_create" is called.
> Most of my memory leaks tool says 'memory leak of 120
> bytes allocated by calloc in "ptw32_new.c"'.
> Is there any call that will free memory and resources?
> Or there is some other way?

Hi Pankaj,

In your code below you have the comment about pthread_join(). Can you 
elaborate?

All threads are joinable by default, so your thread's struct won't be 
freed unless you either join the thread, or make the thread detached 
before it exits.

See the PTHREAD_CREATE_DETACHED attribute and the 
pthread_attr_setdetachstate() function.

Regards.
Ross

> 
> Regards
> 
> Pankaj
> 
> 
> This is my sample code.
> 
> 
> static int washere = 0;
> 
> void * func(void * arg)
> {
>   washere = 1;
>   std::cout<<"Inside The THREAD "<<std::endl;
>   return 0; 
> }
>  
> int main()
> {
>   pthread_t t;
> 
>   assert(pthread_create(&t, NULL, func, NULL) == 0);
> 
>   /* A dirty hack, but we cannot rely on pthread_join
> in this
>      primitive test. */
>   Sleep(2000);
>   assert(washere == 1);
>   std::cout<<"Out side the THREAD "<<std::endl;
>   return 0;
> }
> 
> 
> __________________________________________________
> Yahoo! - We Remember
> 9-11: A tribute to the more than 3,000 lives lost
> http://dir.remember.yahoo.com/tribute



This message may contain privileged and/or confidential information.  If you
have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any
attachments, delete it immediately from your system and notify the sender
promptly by e-mail that you have done so.  Thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: cleaning of memory in pthread_create
  2002-09-10  4:45 pankaj bathwal
@ 2002-09-10  5:13 ` Ross Johnson
  0 siblings, 0 replies; 3+ messages in thread
From: Ross Johnson @ 2002-09-10  5:13 UTC (permalink / raw)
  To: pankaj bathwal; +Cc: pthreads-win32

pankaj bathwal wrote:
> Hi,
> This is regarding freeing of resource and cleaning of
> memory allocated when "pthread_create" is called.
> Most of my memory leaks tool says 'memory leak of 120
> bytes allocated by calloc in "ptw32_new.c"'.
> Is there any call that will free memory and resources?
> Or there is some other way?

Hi Pankaj,

In your code below you have the comment about pthread_join(). Can you 
elaborate?

All threads are joinable by default, so your thread's struct won't be 
freed unless you either join the thread, or make the thread detached 
before it exits.

See the PTHREAD_CREATE_DETACHED attribute and the 
pthread_attr_setdetachstate() function.

Regards.
Ross

> 
> Regards
> 
> Pankaj
> 
> 
> This is my sample code.
> 
> 
> static int washere = 0;
> 
> void * func(void * arg)
> {
>   washere = 1;
>   std::cout<<"Inside The THREAD "<<std::endl;
>   return 0; 
> }
>  
> int main()
> {
>   pthread_t t;
> 
>   assert(pthread_create(&t, NULL, func, NULL) == 0);
> 
>   /* A dirty hack, but we cannot rely on pthread_join
> in this
>      primitive test. */
>   Sleep(2000);
>   assert(washere == 1);
>   std::cout<<"Out side the THREAD "<<std::endl;
>   return 0;
> }
> 
> 
> __________________________________________________
> Yahoo! - We Remember
> 9-11: A tribute to the more than 3,000 lives lost
> http://dir.remember.yahoo.com/tribute



^ permalink raw reply	[flat|nested] 3+ messages in thread

* cleaning of memory in pthread_create
@ 2002-09-10  4:45 pankaj bathwal
  2002-09-10  5:13 ` Ross Johnson
  0 siblings, 1 reply; 3+ messages in thread
From: pankaj bathwal @ 2002-09-10  4:45 UTC (permalink / raw)
  To: pthreads-win32

Hi,
This is regarding freeing of resource and cleaning of
memory allocated when "pthread_create" is called.
Most of my memory leaks tool says 'memory leak of 120
bytes allocated by calloc in "ptw32_new.c"'.
Is there any call that will free memory and resources?
Or there is some other way?

Regards

Pankaj


This is my sample code.


static int washere = 0;

void * func(void * arg)
{
  washere = 1;
  std::cout<<"Inside The THREAD "<<std::endl;
  return 0; 
}
 
int main()
{
  pthread_t t;

  assert(pthread_create(&t, NULL, func, NULL) == 0);

  /* A dirty hack, but we cannot rely on pthread_join
in this
     primitive test. */
  Sleep(2000);
  assert(washere == 1);
  std::cout<<"Out side the THREAD "<<std::endl;
  return 0;
}


__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-10 12:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-10  5:28 cleaning of memory in pthread_create Bossom, John
  -- strict thread matches above, loose matches on Subject: below --
2002-09-10  4:45 pankaj bathwal
2002-09-10  5:13 ` Ross Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).