TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Herbert Rosenau
from: Jonathan de Boyne Pollard
date: 1999-08-30 10:39:08
subject: Terminating threads clean

 HR> Most (but not all) OS/2 APIs calls DosExitCritSec() under cover. So
 HR> you should not use any API (system, runtime, library) unless you know
 HR> that this function would never call a system API.

Actually, that's not quite the right explanation.  

The reason not to call APIs is as explained in the CP Guide and Reference. 
(The CPREF talks about "dynamic link library calls", but it is really talking
about APIs in any arbitrary libraries.  Even statically linked libraries can
be a problem if they use semaphores internally.)  If a second thread had been
already in that API when it was blocked by the first thread entering the
criticical section, then that second thread will possibly be holding a mutex
semaphore that restricts access to the internals of that API.  If the first
thread then attempts to use that API, it will block on the mutex whilst
holding the critical section, and the two threads will be deadlocked.

 ¯ JdeBP ®

--- FleetStreet 1.22 NR
2604/104
* Origin: JdeBP's point, using Squish (2:257/609.3)

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™.