ID Number: Q76814
1.10 1.11 4.20
OS/2
Summary:
SYMPTOMS
An OS/2 application will appear to hang if dbclose() or dbexit() is
placed in the OS/2 exit routine.
CAUSE
When exiting an OS/2 program, all threads belonging to that
application are first closed. Then the exit routine is run in the
context of the main thread, the only remaining running thread.
When an OS/2 DB-LIBRARY (db-lib) program opens a connection to SQL
Server using the dbopen() function, DB-LIBRARY creates a new
thread for that application to manage the DBPROCESS connection.
Thus all DB-LIBRARY applications are multithreaded applications,
and DB-LIBRARY handles all the multithreading automatically.
In addition, DB-LIBRARY uses semaphores to control access to the
DBPROCESS connections. Many OS/2 DB-LIBRARY functions first wait
on the DBPROCESS semaphore before proceeding, dbclose() and
dbexit() among them. When this semaphore is cleared, the DBPROCESS
is available and the function can proceed.
When exiting an OS/2 DB-LIBRARY application, all the DBPROCESS
connection threads created by DB-LIBRARY are first closed by OS/2.
Then the exit routine is run in the context of the main thread. If
dbclose() or dbexit() is run in the exit routine, it first waits
on the DBPROCESS semaphore. However, the DBPROCESS thread has
already been closed by OS/2, thus the semaphore can never be
cleared. As a result, dbclose() or dbexit() will wait forever on a
semaphore that will never be cleared.
RESOLUTION
Because of the architecture of DB-LIBRARY, dbclose() or dbexit()
cannot be called in an OS/2 exit routine registered with
DosExitList().
Additional reference words: dblib 1.10 1.11 4.20