On Fri, Oct 30, 2009 at 3:12 PM, Jeremy Orlow <[email protected]> wrote:
> I've spent a good deal of this week trying to track down what turned out to > be a simple but fairly common problem: I forgot virtual dispatch only > partially works in destructors. There have been several email threads about > this, but it still bites us form time to time, so I thought it was worth > another reminder. > > > Details: > I subclassed ChromeThread which subclasses base::Thread. base::Thread > calls CleanUp on the thread right before termination. CleanUp is virtual. > Both ChromeThread and my class override CleanUp(). base::Thread calls > Stop() in its destructor to stop the thread (if it hasn't already been > stopped). But by the time you hit destruction, the vtable is no longer > available and thus the destructor of base::Thread (and anything it calls) > does NOT have access to the vtable of ChromeThread (or my class). So, if > you don't explicitly call Stop(), your subclass's CleanUp method will NOT be > called. Thus the thread was going away without my CleanUp method ever being > called. > > Obviously this affects more than just base::Thread. And this is also how > you can hit errors with pure virtual methods being called. > > J > Suggestion: don't call CleanUp in the destructor, but check that someone did. Antoine --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: [email protected] View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---
