正文
异常安全在某种意义上来说就像怀孕。。。但是稍微想一想。在没有求婚之前我们不能真正的讨论生殖问题。
假设我们有一个表示GUI菜单的类,这个GUI菜单有背景图片。这个类将被使用在多线程环境中,所以需要mutex进行并发控制。
1 class PrettyMenu { 2 public: 3 ... 4 void changeBackground(std::istream& imgSrc); // change background 5 ... // image 6 7 private: 8 Mutex mutex; // mutex for this object 9 10 Image *bgImage; // current background image11 12 13 14 int imageChanges; // # of times image has been changed15 16 };