Virtualize threadShouldExit()


#1

Hi,

Is it possible to virtualize Thread::threadShouldExit() method ?
I want to have multiple condition to break the thread loop (with some waitable events), and this could avoid changing the thread internal loop’s code.


#2

That doesn’t sound right to me… I don’t like the idea of it being virtual. The purpose of the method is to allow something external to tell the thread that it should stop, so being able to override that feels wrong. Why not just do have a method like:

bool myThreadShouldExit() { return threadShouldExit() || myOtherConditions(); }

…and use that instead?


#3

Sure, it’s possible. I can also override the threadShouldExit() in my code and call the base class version too (but it’s not visible from outside).