for std::thread, change reference args to pointers
I ran into an error "...error: no type named 'type' in class std::result_of..." Google led me to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57716 and I eliminated the error by changing references to pointers as described at http://stackoverflow.com/questions/15235885/invalid-initialization-of-non-const-reference-with-c11-thread
This commit is contained in:
parent
5dc00ba03f
commit
ba74c53ca0
3 changed files with 41 additions and 41 deletions
|
|
@ -46,9 +46,9 @@ void prepareRealRefsFromStreamPos ( instanceStreamPos_t * _spos, instanceRefs &r
|
|||
|
||||
|
||||
/// Used by an individual thread to iterate over the keys of the _fwdRefs / _revRefs multiple times. For each iteration it expects the order of the keys to be the same as dictated by realRefs.
|
||||
void iterateOverRefs ( lazyInstMgr *mgr, instanceRefs &realRefs, bool forward, bool * success ) {
|
||||
void iterateOverRefs ( lazyInstMgr *mgr, instanceRefs * realRefs, bool forward, bool * success ) {
|
||||
const int iterations = 1000;
|
||||
int i, k, instances = realRefs.size();
|
||||
int i, k, instances = realRefs->size();
|
||||
instanceID current;
|
||||
instanceRefs_t * _refs;
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ void iterateOverRefs ( lazyInstMgr *mgr, instanceRefs &realRefs, bool forward, b
|
|||
current = _refs->begin().key;
|
||||
for( i = 0; i < instances; i++ ) {
|
||||
|
||||
if( current != realRefs[i] ) {
|
||||
if( current != (*realRefs)[i] ) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -84,8 +84,8 @@ bool checkRefsSafety( char * fileName, bool forward ) {
|
|||
}
|
||||
|
||||
bool success[2] = { true, true };
|
||||
std::thread first( iterateOverRefs, mgr, realRefs, forward, &success[0] );
|
||||
std::thread second( iterateOverRefs, mgr, realRefs, forward, &success[1] );
|
||||
std::thread first( iterateOverRefs, mgr, &realRefs, forward, &success[0] );
|
||||
std::thread second( iterateOverRefs, mgr, &realRefs, forward, &success[1] );
|
||||
|
||||
first.join();
|
||||
second.join();
|
||||
|
|
@ -144,7 +144,7 @@ bool compareTypeLists( const instanceRefs * v1, const instanceRefs * v2 ) {
|
|||
}
|
||||
|
||||
/// compares the original instances lists with the thread's own view of instances list.
|
||||
void iterateTypeLists( lazyInstMgr * mgr, std::vector< const instanceRefs * > &sameTypeInstances, bool * success ) {
|
||||
void iterateTypeLists( lazyInstMgr * mgr, std::vector< const instanceRefs * > * sameTypeInstances, bool * success ) {
|
||||
const int iterations = 100000;
|
||||
const instanceRefs * refs;
|
||||
int i, k, instances = commonTypes.size();
|
||||
|
|
@ -154,7 +154,7 @@ void iterateTypeLists( lazyInstMgr * mgr, std::vector< const instanceRefs * > &s
|
|||
|
||||
refs = mgr->getInstancesSafely( commonTypes[i] );
|
||||
|
||||
if( !compareTypeLists( refs, sameTypeInstances[i] ) ) {
|
||||
if( !compareTypeLists( refs, (*sameTypeInstances)[i] ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -174,8 +174,8 @@ bool checkTypeInstancesSafety( char * fileName ) {
|
|||
prepareSameTypeInstances( mgr, sameTypeInstances );
|
||||
|
||||
bool success[2] = { true, true };
|
||||
std::thread first( iterateTypeLists, mgr, sameTypeInstances, &success[0] );
|
||||
std::thread second( iterateTypeLists, mgr, sameTypeInstances, &success[1] );
|
||||
std::thread first( iterateTypeLists, mgr, &sameTypeInstances, &success[0] );
|
||||
std::thread second( iterateTypeLists, mgr, &sameTypeInstances, &success[1] );
|
||||
|
||||
first.join();
|
||||
second.join();
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@ void deleteSdaiVec( sdaiVec_t &sdaiVec ) {
|
|||
}
|
||||
}
|
||||
|
||||
void appendInstances( InstMgr * im, sdaiVec_t &sdaiVec, int offset, int stride, int limit ) {
|
||||
void appendInstances( InstMgr * im, sdaiVec_t * sdaiVec, int offset, int stride, int limit ) {
|
||||
SDAI_Application_instance * sai;
|
||||
for( int i = offset; i < limit; i+=stride ) {
|
||||
sai = new SDAI_Application_instance( i+1 );
|
||||
sai->eDesc = new EntityDescriptor( dummyEDescNames[i].c_str(), ( Schema * ) NULL, LTrue, LFalse );
|
||||
sdaiVec[i] = sai;
|
||||
(*sdaiVec)[i] = sai;
|
||||
im->Append( sai, completeSE );
|
||||
}
|
||||
}
|
||||
|
||||
void deleteInstances( InstMgr * im, sdaiVec_t &sdaiVec, int offset, int stride, int limit ) {
|
||||
void deleteInstances( InstMgr * im, sdaiVec_t * sdaiVec, int offset, int stride, int limit ) {
|
||||
for( int i = offset; i < limit; i+=stride ) {
|
||||
im->Delete( sdaiVec[i] );
|
||||
sdaiVec[i] = 0;
|
||||
im->Delete( (*sdaiVec)[i] );
|
||||
(*sdaiVec)[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,8 +80,8 @@ bool checkInstMgrAppendOnlyThreadSafety() {
|
|||
|
||||
//simulate the work done by two threads
|
||||
sdaiVec_t sdaiVecOld( size );
|
||||
appendInstances( imExpected, sdaiVecOld, 0, 2, size );
|
||||
appendInstances( imExpected, sdaiVecOld, 1, 2, size );
|
||||
appendInstances( imExpected, &sdaiVecOld, 0, 2, size );
|
||||
appendInstances( imExpected, &sdaiVecOld, 1, 2, size );
|
||||
std::cout << "Checking thread safety of InstMgr in Append Operation..." ;
|
||||
|
||||
int i, iterations = 1000;
|
||||
|
|
@ -89,8 +89,8 @@ bool checkInstMgrAppendOnlyThreadSafety() {
|
|||
InstMgr * imActual = new InstMgr( 0 );
|
||||
sdaiVec_t sdaiVecNew( size );
|
||||
|
||||
std::thread first( appendInstances, imActual, sdaiVecNew, 0, 2, size );
|
||||
std::thread second( appendInstances, imActual, sdaiVecNew, 1, 2, size );
|
||||
std::thread first( appendInstances, imActual, &sdaiVecNew, 0, 2, size );
|
||||
std::thread second( appendInstances, imActual, &sdaiVecNew, 1, 2, size );
|
||||
|
||||
first.join();
|
||||
second.join();
|
||||
|
|
@ -125,9 +125,9 @@ bool checkInstMgrDeleteOnlyThreadSafety() {
|
|||
//simulate the work done by two threads
|
||||
|
||||
sdaiVec_t sdaiVecOld( size );
|
||||
appendInstances( imExpected, sdaiVecOld, 0, 1, size );
|
||||
deleteInstances( imExpected, sdaiVecOld, 0, 2, size );
|
||||
deleteInstances( imExpected, sdaiVecOld, 1, 2, size );
|
||||
appendInstances( imExpected, &sdaiVecOld, 0, 1, size );
|
||||
deleteInstances( imExpected, &sdaiVecOld, 0, 2, size );
|
||||
deleteInstances( imExpected, &sdaiVecOld, 1, 2, size );
|
||||
std::cout << "Checking thread safety of InstMgr in Delete Operation..." ;
|
||||
|
||||
int i, iterations = 1000;
|
||||
|
|
@ -135,9 +135,9 @@ bool checkInstMgrDeleteOnlyThreadSafety() {
|
|||
InstMgr * imActual = new InstMgr( 0 );
|
||||
sdaiVec_t sdaiVecNew( size );
|
||||
|
||||
appendInstances( imActual, sdaiVecNew, 0, 1, size ); //Preparetion
|
||||
std::thread first( deleteInstances, imActual, sdaiVecNew, 0, 2, size );
|
||||
std::thread second( deleteInstances, imActual, sdaiVecNew, 1, 2, size );
|
||||
appendInstances( imActual, &sdaiVecNew, 0, 1, size ); //Preparetion
|
||||
std::thread first( deleteInstances, imActual, &sdaiVecNew, 0, 2, size );
|
||||
std::thread second( deleteInstances, imActual, &sdaiVecNew, 1, 2, size );
|
||||
|
||||
first.join();
|
||||
second.join();
|
||||
|
|
@ -172,9 +172,9 @@ bool checkInstMgrAppendDeleteThreadSafety() {
|
|||
//simulate the work done by two threads
|
||||
|
||||
sdaiVec_t sdaiVecOld( size );
|
||||
appendInstances( imExpected, sdaiVecOld, 0, 2, size );
|
||||
appendInstances( imExpected, sdaiVecOld, 1, 2, size );
|
||||
deleteInstances( imExpected, sdaiVecOld, 0, 2, size );
|
||||
appendInstances( imExpected, &sdaiVecOld, 0, 2, size );
|
||||
appendInstances( imExpected, &sdaiVecOld, 1, 2, size );
|
||||
deleteInstances( imExpected, &sdaiVecOld, 0, 2, size );
|
||||
std::cout << "Checking thread safety of InstMgr in Append-Delete Operation..." ;
|
||||
|
||||
int i, iterations = 1000;
|
||||
|
|
@ -182,9 +182,9 @@ bool checkInstMgrAppendDeleteThreadSafety() {
|
|||
InstMgr * imActual = new InstMgr( 0 );
|
||||
sdaiVec_t sdaiVecNew( size );
|
||||
|
||||
appendInstances( imActual, sdaiVecNew, 0, 2, size ); //Preparation
|
||||
std::thread first( appendInstances, imActual, sdaiVecNew, 1, 2, size );
|
||||
std::thread second( deleteInstances, imActual, sdaiVecNew, 0, 2, size );
|
||||
appendInstances( imActual, &sdaiVecNew, 0, 2, size ); //Preparation
|
||||
std::thread first( appendInstances, imActual, &sdaiVecNew, 1, 2, size );
|
||||
std::thread second( deleteInstances, imActual, &sdaiVecNew, 0, 2, size );
|
||||
|
||||
first.join();
|
||||
second.join();
|
||||
|
|
|
|||
|
|
@ -66,19 +66,19 @@ void deleteInstanceList( sdaiVec_t & sdaiVec ) {
|
|||
}
|
||||
|
||||
// appends the sdaiApplication_instances from a certain section of the list to sai. (upper and lower limits are inclusive)
|
||||
void appendListTo( SDAI_Application_instance * sai, sdaiVec_t & sdaiVec, int llimit, int ulimit ) {
|
||||
void appendListTo( SDAI_Application_instance * sai, sdaiVec_t * sdaiVec, int llimit, int ulimit ) {
|
||||
for( int i = llimit; i <= ulimit; i++ ) {
|
||||
sai->AppendMultInstance( sdaiVec[i] );
|
||||
sai->AppendMultInstance( (*sdaiVec)[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// searches for the sdaiApplication_instances belonging to ahe certain section of the list from sai. (upper and lower limits are inclusive)
|
||||
// nullAllowedIndex marks the index after which GetMiEntity is allowed to return a NULL value
|
||||
void searchForElements( SDAI_Application_instance * sai, sdaiVec_t & sdaiVec, int llimit, int ulimit, int nullAllowedIndex, bool * errorInFinding ) {
|
||||
void searchForElements( SDAI_Application_instance * sai, sdaiVec_t * sdaiVec, int llimit, int ulimit, int nullAllowedIndex, bool * errorInFinding ) {
|
||||
SDAI_Application_instance * saiFound;
|
||||
for( int i = llimit; i <= ulimit; i++ ) {
|
||||
saiFound = sai->GetMiEntity( EntityNames[i].c_str() );
|
||||
if( saiFound != sdaiVec[i] ) {
|
||||
if( saiFound != (*sdaiVec)[i] ) {
|
||||
if( saiFound == NULL && i >= nullAllowedIndex ) {
|
||||
continue;
|
||||
} else if( i < nullAllowedIndex ) {
|
||||
|
|
@ -129,10 +129,10 @@ bool checkAddAddInstance() {
|
|||
createInstanceList( sdaiVec );
|
||||
size = sdaiVec.size();
|
||||
|
||||
appendListTo( sdaiVec[0], sdaiVec, 1, 4 ); //Initializing List before test
|
||||
appendListTo( sdaiVec[0], &sdaiVec, 1, 4 ); //Initializing List before test
|
||||
|
||||
std::thread first( appendListTo, sdaiVec[0], sdaiVec, 5, size/2 );
|
||||
std::thread second( appendListTo, sdaiVec[4], sdaiVec, ( size/2 )+1 , size-1 );
|
||||
std::thread first( appendListTo, sdaiVec[0], &sdaiVec, 5, size/2 );
|
||||
std::thread second( appendListTo, sdaiVec[4], &sdaiVec, ( size/2 )+1 , size-1 );
|
||||
|
||||
first.join();
|
||||
second.join();
|
||||
|
|
@ -163,17 +163,17 @@ bool checkAddAddGetInstance() {
|
|||
createInstanceList( sdaiVec );
|
||||
size = sdaiVec.size();
|
||||
|
||||
appendListTo( sdaiVec[0], sdaiVec, 1, 4 ); //Initializing List before test
|
||||
appendListTo( sdaiVec[0], &sdaiVec, 1, 4 ); //Initializing List before test
|
||||
|
||||
// The elements added by the two threads are in the ratio 1:3
|
||||
std::thread first( appendListTo, sdaiVec[0], sdaiVec, 5, size/4 );
|
||||
std::thread second( appendListTo, sdaiVec[4], sdaiVec, ( size/4 )+1 , size-1 );
|
||||
std::thread first( appendListTo, sdaiVec[0], &sdaiVec, 5, size/4 );
|
||||
std::thread second( appendListTo, sdaiVec[4], &sdaiVec, ( size/4 )+1 , size-1 );
|
||||
|
||||
first.join();
|
||||
|
||||
bool errorInFinding;
|
||||
//search for first half of the sdaiApplication_instances. 1/4 elements will be present. rest 1/4 elements may / may not be present
|
||||
std::thread third( searchForElements, sdaiVec[0], sdaiVec, 0, size/2, size/4, &errorInFinding );
|
||||
std::thread third( searchForElements, sdaiVec[0], &sdaiVec, 0, size/2, size/4, &errorInFinding );
|
||||
|
||||
second.join();
|
||||
third.join();
|
||||
|
|
|
|||
Loading…
Reference in a new issue