Thread View: comp.os.os2.programmer
3 messages
3 total messages
Started by Kenneth Porter
Mon, 20 May 1991 07:01
Recovering a Dead Thread's Stack, etc.
Author: Kenneth Porter
Date: Mon, 20 May 1991 07:01
Date: Mon, 20 May 1991 07:01
13 lines
982 bytes
982 bytes
How can I tell when a thread is dead and its resources (especially its stack) can be reclaimed? Presumably the thread can't free its own stack since it needs it to call DosExit(). One can't tell that a thread is dead by testing for its ID with, say, DosSuspendThread() (looking for the ERROR_INVALID_THREADID) since another thread might be created that would pick up a dying thread's ID. Presumably _beginthread() accomplishes the stack reclamation, since my company has an application that spawns short-run threads left and right with it and it doesn't lose memory over time. Ken (shiva@well.sf.ca.us)
Re: Recovering a Dead Thread's Stack, etc.
Author: Mark Towfiq
Date: Tue, 21 May 1991 10:31
Date: Tue, 21 May 1991 10:31
26 lines
1902 bytes
1902 bytes
>>>>> 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
Re: Recovering a Dead Thread's Stack, etc.
Author: larrys
Date: Tue, 21 May 1991 14:19
Date: Tue, 21 May 1991 14:19
33 lines
2085 bytes
2085 bytes
In <24884@well.sf.ca.us>, shiva@well.sf.ca.us (Kenneth Porter) writes: > >How can I tell when a thread is dead and its resources >(especially its stack) can be reclaimed? Presumably the thread >can't free its own stack since it needs it to call DosExit(). >One can't tell that a thread is dead by testing for its ID >with, say, DosSuspendThread() (looking for the >ERROR_INVALID_THREADID) since another thread might be created >that would pick up a dying thread's ID. Presumably >_beginthread() accomplishes the stack reclamation, since my >company has an application that spawns short-run threads left >and right with it and it doesn't lose memory over time. > >Ken (shiva@well.sf.ca.us) I don't know of a way to do this. I had a rather large discussion with a colleage yesterday about designing for multithreading. I will be sending a large posting with advantages/disadvantages of various multithreaded programming techniques soon. How do you know the application mentioned isn't losing memory? Are you using some sort of memory utility? Cheers, Larry Salomon, Jr. (aka 'Q') LARRYS@YKTVMV.BITNET OS/2 Applications and Tools larrys@ibmman.watson.ibm.com IBM T.J. Watson Research Center larrys@eng.clemson.edu Yorktown Heights, NY Disclaimer: The statements and/or opinions stated above are strictly my own and do not reflect the views of my employer. Additionally, I have a reputation for being obnoxious, so don't take any personal attacks too seriously.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads