Comment 10 for bug 885802

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

> How would you manage the new epicsThread objects that creates without leaking memory?

See how a good c++ API forces you to think about resource cleanup! For unittest code the answer is usually easy, and epicsAtomicTest is no exception. Keep them on the stack.

The test cases each start thread(s), wait, then test to if the thread did the right thing. This is naturally the point where the threads would join, and also serves to enforce isolation of each test case (which reuse globals).

imo, best (as in ideal) C++ API design practice would ultimately tie all resource allocation to a stack frame. This has a number of benefits, including exception safety and ease of unit testing. And of course it is pleasing when valgrind tells you "no leaks are possible".