68 static void read_arrayview_in_thread(RCP<ArrayView<int>> shared_arrayview,
 
   69   int expectedValue, std::atomic<int> & countErrors) {
 
   71   while (!ThreadTestManager::s_bAllowThreadsToRun) {}
 
   72   for( 
int n = 0; 
n < 1000; ++
n) {
 
   74       iter < shared_arrayview->end(); ++iter) {
 
   75       int readAValueByIterator = *iter;
 
   77       if (readAValueByIterator != expectedValue) {
 
  110   const int setValue = 67359487; 
 
  111   const int arraySize = 10; 
 
  112   std::atomic<int> countErrors(0); 
 
  113   for (
int testCycle = 0; testCycle < numTests; ++testCycle) {
 
  115       std::vector<std::thread> threads;
 
  116       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  117       Array<int> array(arraySize, setValue); 
 
  118       RCP<ArrayView<int>> arrayview_rcp = 
rcp(
new ArrayView<int>(array));
 
  120       for (
int i = 0; i < numThreads; ++i) {
 
  121         threads.push_back( std::thread(read_arrayview_in_thread,
 
  122           arrayview_rcp, setValue, std::ref(countErrors)) );
 
  125       ThreadTestManager::s_bAllowThreadsToRun = 
true;   
 
  126       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  132     convenience_log_progress(testCycle, numTests);  
 
  149 static void scramble_memory(
int scrambleValue, 
int testArraySize,
 
  150   int finishWhenThisThreadCountCompletes) {
 
  151   while (!ThreadTestManager::s_bAllowThreadsToRun) {}
 
  156     #define ARRAY_SCRAMBLE_SIZE 100 
  157     std::vector<int> * tempPtrArray[ARRAY_SCRAMBLE_SIZE];
 
  158     for (
int n = 0; 
n < ARRAY_SCRAMBLE_SIZE; ++
n) {
 
  162       tempPtrArray[
n] = 
new std::vector<int>(testArraySize, scrambleValue);
 
  164     for (
int n = 0; 
n < ARRAY_SCRAMBLE_SIZE; ++
n) {
 
  165       delete tempPtrArray[
n];
 
  167     if (ThreadTestManager::s_countCompletedThreads >=
 
  168       finishWhenThisThreadCountCompletes) {
 
  178 static void share_arrayview_to_threads(ArrayView<int> shared_arrayview,
 
  179   int theTestValue, Cycle_Index_Tracker & index_tracker) {
 
  180   while (!ThreadTestManager::s_bAllowThreadsToRun) {}
 
  184       bool bCheckStatus = ThreadTestManager::s_bMainThreadSetToNull;
 
  187       int tryToReadAValue = shared_arrayview[0];
 
  188       index_tracker.trackCycle = cycle;
 
  189       if (tryToReadAValue != theTestValue) {
 
  193         index_tracker.scambledMemory = cycle;
 
  197         index_tracker.unknownError = cycle;
 
  205   catch (DanglingReferenceError) {
 
  207     index_tracker.danglingReference = cycle;
 
  210     std::cout << std::endl << 
"Unknown and unhandled exception!" << std::endl;
 
  213   ++ThreadTestManager::s_countCompletedThreads;
 
  250   const int theTestValue = 66387; 
 
  251   const int scrambleValue = 572778; 
 
  252   const int testArraySize = 3;
 
  255   int countDanglingReferences = 0;
 
  256   int scrambledMemoryEvents = 0;
 
  257   int unknownErrors = 0;
 
  260   int finishWhenThisThreadCountCompletes = numThreads - 1;
 
  261   for (
int testCycle = 0; testCycle < numTests; ++testCycle) {
 
  263       ThreadTestManager::s_countCompletedThreads = 0;
 
  266       ArrayRCP<int> arrayrcp = 
arcp(
rcp(
 
  267         new std::vector<int>(testArraySize, theTestValue)));
 
  269       ArrayView<int> shared_arrayview = arrayrcp();
 
  271       ThreadTestManager::s_bAllowThreadsToRun = 
false;
 
  273       ThreadTestManager::s_bMainThreadSetToNull = 
false;
 
  275       Cycle_Index_Tracker index_tracker[numThreads];
 
  277       std::vector<std::thread> threads;
 
  278       for (
int i = 0; i < numThreads; ++i) {
 
  288             threads.push_back(std::thread(scramble_memory, scrambleValue,
 
  289               testArraySize, finishWhenThisThreadCountCompletes));
 
  297             threads.push_back(std::thread(share_arrayview_to_threads,
 
  298               shared_arrayview, theTestValue, std::ref(index_tracker[i])));
 
  304       ThreadTestManager::s_bAllowThreadsToRun = 
true;
 
  306       while (index_tracker[1].trackCycle < 1) {}
 
  310       ThreadTestManager::s_bMainThreadSetToNull = 
true;   
 
  312       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  316       for (
unsigned int i = 0; i < threads.size(); ++i) {
 
  317         if (index_tracker[i].danglingReference != -1) {
 
  318           ++countDanglingReferences; 
 
  320         if (index_tracker[i].scambledMemory != -1 ) {
 
  325           ++scrambledMemoryEvents;
 
  327         if (index_tracker[i].unknownError != -1 ) {
 
  333     convenience_log_progress(testCycle, numTests);  
 
  339   int requiredDanglingReferenceCount = (numThreads-1) * numTests;
 
  340   bool bDanglingReferenceDetectionCountIsOK = (countDanglingReferences ==
 
  341     requiredDanglingReferenceCount);
 
  344   if( !bDanglingReferenceDetectionCountIsOK ) {
 
  345     std::cout << std::endl << 
"Detected " << countDanglingReferences <<
 
  346       " Dangling References but should have found " <<
 
  347       requiredDanglingReferenceCount << 
"." << std::endl;
 
  353     std::cout << 
"Danglers: " << countDanglingReferences << 
" Scrambles: " <<
 
  354       scrambledMemoryEvents << 
" ";
 
  358   if (unknownErrors != 0) {
 
  359     std::cout << std::endl << 
"Detected " << unknownErrors <<
 
  360       " dangling references were missed which should have been detected." 
  364   TEST_ASSERT( bDanglingReferenceDetectionCountIsOK )
 
  369 #endif // TEUCHOS_DEBUG 
Dangling reference error exception class. 
 
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
 
#define TEST_ASSERT(v1)
Assert the given statement is true. 
 
pointer iterator
Type of a nonconst iterator. 
 
#define TEUCHOS_THREAD_SAFE_UNIT_TESTS_THREADS_USED
 
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object. 
 
#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. 
 
Templated array class derived from the STL std::vector. 
 
Smart reference counting pointer class for automatic garbage collection. 
 
Range error exception class. 
 
Reference-counted smart pointer for managing arrays. 
 
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...