TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: MIKE RUSKAI
from: Mario Semo
date: 1999-08-30 09:04:06
subject: Terminating threads clean

Hallo MIKE!

Antwort auf eine Message von MIKE RUSKAI an VITUS JENSEN:

 VJ>> You can use DosWaitThread so that you can recover thread resources
 VJ>> when the thread ends, or to synchronize the execution of a thread
 VJ>> with the execution of other threads. === DosWaitThread is used to
 VJ>> wait for termination of threads within a process. It is usually used
 VJ>> so that thread resources (for example, the stack) can be recovered
 VJ>> when a thread ends. ===

 MR> FWIW, I compiled a quickie to test this (as I had never used 
 MR> DosWaitThread()), and the results seem to indicate that resources are
 MR> not  lost. 

 MR> So, at the very least, the thread's stack is recovered by the system
 MR> as  soon as the thread ends, regardless of whether or not
 MR> DosWaitThread() is  called.

Ive always assumed, that this is historical from OS2 1.x times. here the user
allocates the stack and so the use definitly have to know, when the thread
finally terminated.

but under 2.x times i assumed there is a thread exit routine inserted by the
OS2 itself.  and this function should run, when the thread low level
terminates. at this point the thread resources are not need anymore, and so
can savely be freed.

there is one scenario when you loose resources in threads:
  create a thread with _beginthread
  create C++ objects on the (thread) stack and let the ctors allocate
resources.
  then terminate the thread with _endthread (selftermination)

then no destructors are called and so the resources are lost.


Servus, Mario!

--- FleetStreet 1.21 PR#2
2604/104
* Origin: LC/32 Development Team, http://www.kirchnersoft.com (2:310/14.11)

SOURCE: echoes via The OS/2 BBS

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.