| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Thereby Ends A Thread |
PC>
> I found a way to wait for a session started with DosStartSession to end.
PC>
Why not use a termination queue like the rest of us ?
PC>
> // ...
> rc = DosSuspendThread(pdata->tidReadThread);
> rc = DosStartSession(&StartData, &SessID, &pid);
> WaitForSession(&pdata->tidHsl, SessID);
> rc = DosResumeThread(pdata->tidReadThread);
> WinTerminate(hab);
> _endthread();
> }
PC>
Incidentally, _endthread() is redundant just before the return from a
thread procedure.
I once had to maintain code that did this in a thread procedure.
{
MyClass thingy ;
// ...
DosEnterCritSec() ;
WinPostMsg(MainWindow, WM_I_HAVE_FINISHED, 0, 0) ;
WinDestroyMsgQueue(hmq) ;
WinTerminate(hab) ;
_endthread() ;
DosExitCritSec() ;
}
Sometimes the application would take several minutes to exit a thread.
Sometimes the application would crash. Sometimes the entire system
would hang. Sometimes not even Ctrl-Esc would shift it.
And, of course, according the the CPU speed and current load of the
machine, the result would vary.
It was murder to debug, not leastly because once a colleage (who had
the debug kernel) had spotted the flaw I found it replicated all over
the place in the application.
The flaw was twofold. Firstly, the DosExitCritSec() was never being
called, and destructors for local objects were not being run, since
_endthread() never returns. Secondly, there are many operations that
shouldn't be performed in critical sections, including anything to do
with Presentation Manager messages and message queues.
Morals ?
Don't use _endthread() at the end of a thread procedure, especially if
you use C++.
Don't use critical sections as a quick hack workaround (which is what
I later found out that this was), because they bite. I'd put them
right up there in the hall of infamy display case alongside Peter's
DosSuspendThread and DosKillThread.
> JdeBP <
___
X MegaMail 2.10 #0:
--- Maximus/2 3.00
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 517 628 713/888 800/1 7877/2809 @PATH: 440/4 141/209 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
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™.