Chapter 4. Concurrency

Table of Contents

Which DB Handles are Free-Threaded
Locks, Blocks, and Deadlocks
Locks
Blocks
Deadlocks
The Locking Subsystem
Configuring the Locking Subsystem
Configuring Deadlock Detection
Resolving Deadlocks
Setting Transaction Priorities
Isolation
Supported Degrees of Isolation
Reading Uncommitted Data
Committed Reads
Using Snapshot Isolation
Transactional Cursors and Concurrent Applications
Using Cursors with Uncommitted Data
Exclusive Database Handles
Read/Modify/Write
No Wait on Blocks
Reverse BTree Splits

DB offers a great deal of support for multi-threaded and multi-process applications even when transactions are not in use. Many of DB's handles are thread-safe, or can be made thread-safe by providing the appropriate flag at handle creation time, and DB provides a flexible locking subsystem for managing databases in a concurrent application. Further, DB provides a robust mechanism for detecting and responding to deadlocks . All of these concepts are explored in this chapter.

Before continuing, it is useful to define a few terms that will appear throughout this chapter:

Which DB Handles are Free-Threaded

The following describes to what extent and under what conditions individual handles are free-threaded.

  • DB_ENV

    Free-threaded so long as the DB_THREAD flag is provided to the environment open() method.

  • DB

    Free-threaded so long as the DB_THREAD flag is provided to the database open() method, or if the database is opened using a free-threaded environment handle.

  • DBC

    Cursors are not free-threaded. However, they can be used by multiple threads of control so long as the application serializes access to the handle.

  • DB_TXN

    Access must be serialized by the application across threads of control.