Download C - Oracle Documentation

Transcript
Advanced Topics
B
This appendix contains a collection of topics. Not all drivers need to be
concerned with the issues addressed.
Multithreading
This section supplements the guidelines presented in Chapter 4,
“Multithreading,” for writing an MT-safe driver, a driver that safely supports
multiple threads.
Lock Granularity
Here are some issues to consider when deciding on how many locks to use in a
driver:
•
•
•
•
•
•
The driver should allow as many threads as possible into the driver: this
leads to fine-grained locking.
However, it should not spend too much time executing the locking
primitives: this approach leads to coarse-grained locking.
Moreover, the code should be simple and maintainable.
Avoid lock contention for shared data.
Write reentrant code wherever possible. This makes it possible for many
threads to execute without grabbing any locks.
Use locks to protect the data and not the code path.
297