I have an AbstractAgent base class that manages a background thread. The actual work done in the background thread is accomplished through a pure virtual function call.

Here's the problem: because the base class is initialized prior to the derived class, there is a race condition in which the pure virtual call might occur before the derived class is initialized. Likewise, on teardown the derived class might deconstruct before the base class destructor has a chance to stop the thread.

I'd like to know if there are any well-known patterns for dealing with this problem. All I can think of is providing start() and stop() methods which can be called from the most-derived class's constructor/destructor, but that strikes me as inelegant.