Newsgroups: comp.os.os2.programmer
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!clarkson!grape.ecs.clarkson.edu!towfiq
From: towfiq@FTP.COM (Mark Towfiq)
Subject: Re: Recovering a Dead Thread's Stack, etc.
Reply-To: towfiq@FTP.COM
Organization: FTP Software, Inc., Wakefield, MA
Distribution: comp
Date: 21 May 91 10:31:01
Message-ID: <TOWFIQ.91May21103101@babyoil.FTP.COM>
In-Reply-To: shiva@well.sf.ca.us's message of 20 May 91 07:01:25 GMT
References: <24884@well.sf.ca.us>
Sender: usenet@grape.ecs.clarkson.edu

>>>>> On 20 May 91 07:01:25 GMT, shiva@well.sf.ca.us (Kenneth Porter)
>>>>> said:

Ken> How can I tell when a thread is dead and its resources
Ken> (especially its stack) can be reclaimed?  Presumably the thread
Ken> can't free its own stack since it needs it to call DosExit(). 
Ken> One can't tell that a thread is dead by testing for its ID
Ken> with, say, DosSuspendThread() (looking for the
Ken> ERROR_INVALID_THREADID) since another thread might be created
Ken> that would pick up a dying thread's ID.  Presumably
Ken> _beginthread() accomplishes the stack reclamation, since my
Ken> company has an application that spawns short-run threads left
Ken> and right with it and it doesn't lose memory over time.

Well, you sort of answered the question yourself.  _beginthread() in C
6.0 does do the re-use/reclamation for you, since it can keep track of
which threads are used.  As far as a thread started by
DosCreateThread() goes, however (a thread which cannot call any C
run-time functions, by the way), the only reliable way I can think of
reclaiming such things is to have your thread set a flag or such upon
exit.
--
Mark Towfiq, FTP Software, Inc.                                  towfiq@FTP.COM
Work No.: +1 617 246 0900			      Home No.: +1 617 488 2818

  "The Earth is but One Country, and Mankind its Citizens" -- Baha'u'llah
