TXBase::InstanceCount is not thread-safe
Borland's Object Windows Library for the modern age
Brought to you by:
jogybl,
sebas_ledesma
Also, the intended use of the variable seems to be to detect that exceptions are in flight, but this is unreliable in itself because a program can instantiate TXBase without throwing it immediately (or ever), e.g. to store the current exception in flight and rethrow another (convert/upgrade exceptions). Also, a program can throw exceptions not derived from TXBase. There are other better ways of detecting whether an exception is in flight (see std::uncaught_exception, but note undefined behaviour in multi-threaded programs).
InstanceCount is used in only one place in OWLNext; TXRegistry::Check use it seemingly for the purpose of detecting if exceptions are in flight. This seems ill-adviced. If InstanceCount > 0, despite the 'stat' argument indicating an error condition, the Check function will just return, and program-flow continues with possibly unexpected results. An exception should always be thrown in Check, even if this leads to program shutdown during stack unwinding. A safe program should use exception handling to ensure that exceptions are handled during stack unwinding (i.e. in destructors). Ignoring error conditions is not a solution.
For these reasons I propose that we simply remove TXBase::InstanceCount and make TXRegistry::Check always throw on errors.
Last edit: Vidar Hasfjord 2012-09-28
This issue was eliminated by the removal of TXBase::InstanceCount in revision 1217:
http://owlnext.svn.sourceforge.net/viewvc/owlnext?view=revision&revision=1217