64 static void make_large_number_of_copies(RCP<int> 
ptr) {
 
   65   std::vector<RCP<int> > ptrs(10000, ptr);
 
  101   RCP<int> 
ptr(
new int); 
 
  102   std::vector<std::thread> threads;
 
  103   for (
int i = 0; i < numThreads; ++i) {
 
  104     threads.push_back(std::thread(make_large_number_of_copies, 
ptr));
 
  106   for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  117 static void create_independent_rcp_objects() {
 
  119   while (!ThreadTestManager::s_bAllowThreadsToRun) {}
 
  123     RCP<int> 
ptr( 
new int );
 
  152     std::vector<std::thread> threads;
 
  154     ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  155     for (
int i = 0; i < numThreads; ++i) {
 
  156       threads.push_back(std::thread(create_independent_rcp_objects));
 
  159     ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  160     for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  173 static void create_independent_rcp_without_ownership() {
 
  174   for(
int n = 0; 
n < 10000; ++
n ) {
 
  175     int * intPtr = 
new int;
 
  177     RCP<int> 
ptr( intPtr, 
false );
 
  202     std::vector<std::thread> threads;
 
  203     for (
int i = 0; i < numThreads; ++i) {
 
  204       threads.push_back(std::thread(create_independent_rcp_without_ownership));
 
  206     for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  218 template<
typename SOURCE_RCP_TYPE>
 
  219 static void thread_gets_a_copy_of_rcp(SOURCE_RCP_TYPE 
ptr) {
 
  223   while(!ThreadTestManager::s_bAllowThreadsToRun) {}
 
  251     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  253       CatchMemoryLeak::s_countAllocated = 0;
 
  255       RCP<CatchMemoryLeak> 
ptr(
new CatchMemoryLeak);
 
  257       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  258       std::vector<std::thread> threads;
 
  259       for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
 
  260         threads.push_back(std::thread(
 
  261           thread_gets_a_copy_of_rcp<RCP<CatchMemoryLeak>>, ptr));
 
  267       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  268       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  272       convenience_log_progress(cycleIndex, numCycles);  
 
  273       if (CatchMemoryLeak::s_countAllocated != 0) {
 
  287 void deallocCatchMemoryLeak(CatchMemoryLeak* ptr)
 
  290   ++CatchMemoryLeak::s_countDeallocs;
 
  316     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  317       CatchMemoryLeak::s_countDeallocs = 0; 
 
  319         Teuchos::deallocFunctorDelete<CatchMemoryLeak>(deallocCatchMemoryLeak));
 
  321       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  322       std::vector<std::thread> threads;
 
  323       for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
 
  324         threads.push_back(std::thread(
 
  325           thread_gets_a_copy_of_rcp<RCP<CatchMemoryLeak>>, ptr));
 
  331       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  332       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  336       convenience_log_progress(cycleIndex, numCycles);
 
  337       if (CatchMemoryLeak::s_countDeallocs != 1) {
 
  348 void deallocHandleCatchMemoryLeak(CatchMemoryLeak** handle)
 
  350   ++CatchMemoryLeak::s_countDeallocs;
 
  351   CatchMemoryLeak *ptr = *handle;
 
  378     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  379       CatchMemoryLeak::s_countDeallocs = 0; 
 
  381        Teuchos::deallocFunctorHandleDelete<CatchMemoryLeak>(
 
  382          deallocHandleCatchMemoryLeak));
 
  384       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  385       std::vector<std::thread> threads;
 
  386       for (
unsigned int threadIndex = 0; threadIndex <
 
  387         numThreads; ++threadIndex) {
 
  388         threads.push_back(std::thread(
 
  389           thread_gets_a_copy_of_rcp<RCP<CatchMemoryLeak>>, ptr));
 
  395       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  396       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  400       convenience_log_progress(cycleIndex, numCycles); 
 
  401       if (CatchMemoryLeak::s_countDeallocs != 1) {
 
  413 static void call_release_on_rcp_if_flag_is_set(RCP<CatchMemoryLeak> ptr,
 
  414   int numCopies, 
bool bCallsRelease) {
 
  416   while(!ThreadTestManager::s_bAllowThreadsToRun) {}
 
  441   bool bFailure = 
false;
 
  443     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  444       CatchMemoryLeak::s_countAllocated = 0; 
 
  445       CatchMemoryLeak * pMemoryToLeak = 
new CatchMemoryLeak;
 
  446       RCP<CatchMemoryLeak> 
ptr(pMemoryToLeak);
 
  448       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  449       std::vector<std::thread> threads;
 
  450       for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
 
  451         bool bCallRelease = (threadIndex==0); 
 
  452         threads.push_back(std::thread(call_release_on_rcp_if_flag_is_set,
 
  453           ptr, 1, bCallRelease));
 
  456       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  457       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  460       convenience_log_progress(cycleIndex, numCycles); 
 
  461       if (CatchMemoryLeak::s_countAllocated != 1) {
 
  467         delete pMemoryToLeak;
 
  480 class ExtraDataTest {
 
  482   static RCP<ExtraDataTest<T> > create(T *ptr)
 
  483     { 
return rcp(
new ExtraDataTest(ptr)); }
 
  484   ~ExtraDataTest() { 
delete [] ptr_; } 
 
  487   ExtraDataTest(T *ptr) : ptr_(ptr) {}
 
  490   ExtraDataTest(
const ExtraDataTest&);
 
  491   ExtraDataTest& operator=(
const ExtraDataTest&);
 
  514     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  515       CatchMemoryLeak::s_countAllocated = 0; 
 
  517       RCP<CatchMemoryLeak> 
ptr(
new CatchMemoryLeak[1]);
 
  519       Teuchos::set_extra_data( ExtraDataTest<CatchMemoryLeak>::create(
 
  520         ptr.getRawPtr()), 
"dealloc", Teuchos::inOutArg(ptr));
 
  522       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  523       std::vector<std::thread> threads;
 
  524       for (
unsigned int threadIndex = 0; threadIndex < numThreads;
 
  526         threads.push_back(std::thread(
 
  527           thread_gets_a_copy_of_rcp<RCP<CatchMemoryLeak>>, ptr));
 
  533       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  534       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  538       convenience_log_progress(cycleIndex, numCycles); 
 
  539       if (CatchMemoryLeak::s_countAllocated != 0) {
 
  581     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  582       CatchMemoryLeak::s_countAllocated = 0; 
 
  584       RCP<CatchMemoryLeak> 
ptr(
new CatchMemoryLeak);
 
  586       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  587       std::vector<std::thread> threads;
 
  588       bool bToggleStrong = 
true;
 
  589       for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
 
  591           threads.push_back(std::thread(
 
  592             thread_gets_a_copy_of_rcp<RCP<CatchMemoryLeak>>,
 
  593               ptr.create_strong()));
 
  596           threads.push_back(std::thread(
 
  597             thread_gets_a_copy_of_rcp<RCP<CatchMemoryLeak>>,
 
  600         bToggleStrong = !bToggleStrong;
 
  606       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  607       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  611       convenience_log_progress(cycleIndex, numCycles);  
 
  612       if (CatchMemoryLeak::s_countAllocated != 0) {
 
  623 static std::atomic<int> s_count_successful_conversions(0);
 
  624 static std::atomic<int> s_count_failed_conversions(0);
 
  625 template<
class SOURCE_RCP_TYPE>
 
  626 static void attempt_make_a_strong_ptr(SOURCE_RCP_TYPE ptr) {
 
  628   while(!ThreadTestManager::s_bAllowThreadsToRun) {}
 
  630   RCP<CatchMemoryLeak> possibleStrongPtr = ptr.create_strong_thread_safe();
 
  631   if (possibleStrongPtr.is_null()) {
 
  632     ++s_count_failed_conversions;
 
  635     ++s_count_successful_conversions;
 
  666   s_count_successful_conversions = 0;
 
  667   s_count_failed_conversions = 0;
 
  669     for(
int cycleIndex = 0; cycleIndex < numCycles; ++cycleIndex) {
 
  670       CatchMemoryLeak::s_countAllocated = 0; 
 
  672       RCP<CatchMemoryLeak> 
ptr(
new CatchMemoryLeak);
 
  674       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  675       std::vector<std::thread> threads;
 
  676       bool bCycleStrong = 
true;
 
  677       for (
int threadIndex = 0; threadIndex < numThreads; ++threadIndex) {
 
  679           threads.push_back(std::thread(
 
  680             attempt_make_a_strong_ptr<RCP<CatchMemoryLeak>>,
 
  681               ptr.create_strong()));
 
  684           threads.push_back(std::thread(
 
  685             attempt_make_a_strong_ptr<RCP<CatchMemoryLeak>>,
 
  688         bCycleStrong = !bCycleStrong;
 
  694       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  695       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  699       if (CatchMemoryLeak::s_countAllocated != 0) {
 
  705   std::cout << 
"Weak converted with null " << s_count_failed_conversions <<
 
  706     " times and success " << s_count_successful_conversions
 
  707     << 
" times. We want to see a mix of each. ";
 
#define TEST_INEQUALITY_CONST(v1, v2)
Assert the inequality of v1 and constant v2. 
 
#define TEUCHOS_THREAD_SAFE_UNIT_TESTS_THREADS_USED
 
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2. 
 
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test. 
 
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated. 
 
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions. 
 
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2. 
 
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer. 
 
Smart reference counting pointer class for automatic garbage collection. 
 
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy. 
 
Reference-counted pointer node classes. 
 
static int numActiveRCPNodes()
Print the number of active RCPNode objects currently being tracked. 
 
Reference-counted pointer class and non-member templated function implementations.