Previous: Deadlock Up: Atomicity Next: Pitfalls
Atomicity of member functions is preserved under inheritance. Base classes and derived classes can contain atomic member functions. The atomic members of an object of a derived class behave the same as for a simple class without inheritance. That is, regardless of whether the atomic member is declared in the base class or the derived class, it is an atomic member of the derived class. For example:
class Base { protected: atomic void f(int) {...} };class Derived : private Base { public: atomic int g(void) {...} void h(int i) { f(i); //executes atomically with respect to g() ... } };
In an object of type Derived, instances of g() and f() execute atomically.