Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

9.3 Sharing DBTools.h++ Objects Among Threads

Applications that share DBTools.h++ objects across threads can use an object's internal mutex to control access. This is accomplished through two member functions:

The acquire() function locks the internal mutex, while the release() function unlocks it. Most DBTools.h++ objects provide these functions, as noted in the Class Reference. They are available even in single-threaded environments, where they are no-ops. This maintains portability of applications across both single-threaded and multithreaded environments.

Please note that acquire() and release() must be called in pairs, or deadlock can occur. Deadlock results when an application attempts to acquire a mutex that is not released, frequently because an exception was thrown. To prevent deadlocks, you can use a simple technique called a guard class. In C++, the guard class constructor acquires the mutex at initialization, and the destructor releases it upon destruction. How you use a guard class depends upon whether or not your compiler supports templates. Refer to Section 9.6, Section 9.7, and Section 9.8 for further details.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.