Martin Watt - 2009-07-24

I'd like to test some code for threadsafety. Since I already have unit tests for the code, I was hoping I could simple run multiple instances of each unit test concurrently in different threads and watch for any unit test failures. This does appear to work, and caught some real race conditions in the code. The problem is that when a test fails via a CPPUNIT_ASSERT, it throws a CppUnit::Exception, and if this is from a thread other than the main thread, the exception is not caught and the app terminates:

#0  in raise () from /lib64/tls/
#1  in abort () from /lib64/tls/
#2  in __gnu_cxx::__verbose_terminate_handler () from /usr/lib64/
#3  in __cxa_call_unexpected () from /usr/lib64/
#4  in std::terminate () from /usr/lib64/
#5  in __cxa_throw () from /usr/lib64/
#6  in CppUnit::Asserter::fail (message=@0x409ffff0, sourceLine=@0x40a00050) at Asserter.cpp:22
#7  in ExampleTestCase::testEquals ()

So I'm wondering if there is any way to do this kind of multithreaded testing using cppunit? I could probably even live with the crash, but I'm wondering if there are other subtle problems I'm likely to run into going this way?

Thanks in advance for any help...