Concurrent Reference Counting

We have already investigated two versions of reference counting and established that one (using RCPtr) was faster than the other (using RCIPtr). There's one more important twist on reference counting that we need to evaluate. The third implementation variant handles reference-counted objects in a multithreaded execution environment. In that case, multiple threads may access a reference-counted object concurrently. Therefore, the variable holding the reference count must be protected so that updates are atomic. Atomic updates require a locking mechanism. We have discussed locking classes in Chapter 7, and we reproduce the relevant code subset here:

 class MutexLock { public: MutexLock() {mutex = CreateMutex(NULL, ...

Get Efficient C++ Performance Programming Techniques now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.