ODBC in Multi-Threaded Environments (Thread Safety)

For multi-threaded operating systems, ODBC requires that drivers are thread-safe. The ODBC drivers must ensure multiple threads can safely share the same ODBC handle. The question is how far should the driver go in protecting handles and how much is the responsibility of the application.

At least, the driver should protect handles within ODBC functions. That is, if multiple threads, using the same handle, simultaneously call ODBC functions, the driver should serialize access sufficiently to ensure operations are consistent on the handle. This is function-level thread safety.

The larger consideration is that ODBC handles carry state information between function calls. The ODBC drivers could protect this state information in some cases, but ultimately, some of the responsibility for thread safety falls on the application. The application must provide some synchronization of access to ODBC by multiple threads, even when using thread-safe ODBC drivers.

This article discusses these issues in detail. It describes the problems and provides general, portable solutions.

View Entire Paper | Previous Page | White Papers Search

If you found this page useful, bookmark and share it on: