More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions

I l @ ve RuBoard

Difficulty: 8

In this final chapter of the miniseries, we consider the effects of thread safety on copy-on-write strings. Is lazy copy really an optimization? The answer may surprise you.

  1. Why is Optimized::String (from Item 15) not thread-safe? Give examples.

  2. Demonstrate how to make Optimized::String thread-safe:

    1. assuming there are atomic operations to get, set, and compare integer values; and

    2. assuming there aren't.

  3. What are the effects on performance? Discuss.

I l @ ve RuBoard

Категории