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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.