Item 16. Lazy Optimization, Part 4: Multithreaded Environments

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


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net