public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Ross Johnson <rpj@ise.canberra.edu.au>
To: pankaj bathwal <pbathwal@yahoo.com>
Cc: pthreads-win32@sources.redhat.com
Subject: Re: cleaning of memory in pthread_create
Date: Tue, 10 Sep 2002 05:13:00 -0000	[thread overview]
Message-ID: <3D7DE225.7070809@ise.canberra.edu.au> (raw)
In-Reply-To: <20020910114509.73572.qmail@web14508.mail.yahoo.com>

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



  reply	other threads:[~2002-09-10 12:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-10  4:45 pankaj bathwal
2002-09-10  5:13 ` Ross Johnson [this message]
2002-09-10  5:28 Bossom, John

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D7DE225.7070809@ise.canberra.edu.au \
    --to=rpj@ise.canberra.edu.au \
    --cc=pbathwal@yahoo.com \
    --cc=pthreads-win32@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).