🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.os2.programmer
1 messages
1 total messages Started by Oleg Vishnepolsky Tue, 21 May 1991 19:33
Re: Recovering a Dead Thread's Stack, etc.
#3137
Author: Oleg Vishnepolsky
Date: Tue, 21 May 1991 19:33
30 lines
1942 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)

Microsoft C compiler 6.0 frees application developers of necessity
to allocate their own stack. If you specify stack pointer as NULL,
then run-time library takes care of allocating the stack for you.
Then when the thread dies, the run-time deallocates the stack
for you. This way you bypass the whole problem of recovering the stack.

I am quoting from Microsoft C Advanced Programming Techniques:

"If you specify NULL for the stack address, _beginthread manages
allocation and deallocation of the thread stack for you. This
option is advantageous because it is difficult for your program
to determine when  a thread has terminated, so you cannot know
when to deallocate the thread stack".

Oleg Vishnepolsky
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