This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Linking to cygwin1.dll and msvcrt.dll ?


On Tue, Jul 17, 2001 at 04:01:06PM -0700, Mo DeJong wrote:
> On Wed, 18 Jul 2001, Corinna Vinschen wrote:
> 
> > I'm somehow missing a
> > 
> >        CloseHandle ((HANDLE)code);
> > 
> > at this point which at least closes the handle to the thread. Otherwise
> > the following from MSDN is valid:
> > 
> >     The thread object remains in the system until the thread has
> >     terminated and all handles to it have been closed through a
> >     call to CloseHandle.
> > 
> > Corinna
> 
> That is interesting. The code variable is a local and the
> pointer is not saved. Would this call to CloseHandle()
> need to be done after a call to ExitThread()?

No. After CreateThread() the thread is up and running. The
handle returned by CreateThread() is just the handle for the
parent thread to have control over the child thread. If the
parent is not further interested in controlling the child
it simply closes the handle immediately and forgets about
the child thread:

  if ((thdl = CreateThread (...)) != NULL)
    CloseHandle (thdl):

This is only possible if the thread is not started in a suspended
state, of course. Otherwise the parent would need the handle to
resume the child.

If the parent thread never closes the thread handle, the thread
is similar to a zombie process which still waists system resources
until the process exits.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]