Show
Ignore:
Timestamp:
01/25/08 14:32:12 (10 months ago)
Author:
cneumann
Message:

fixed: MT sync for child fields (should not link parents)

more reliable thread exit for MT test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Carsten_PtrWork2/Source/System/NodeCores/Groups/Misc/testSimpleMT.cpp

    r1041 r1042  
    1717Barrier            *gSyncBarrier; 
    1818 
    19 volatile bool       exitFlag = false; 
     19volatile bool       gExitFlag = false; 
    2020 
    2121class TreePrinter 
     
    103103    //                   +- n2N 
    104104     
     105    bool exitFlag = false; 
     106     
    105107    NodeRefPtr       n0N    = makeCoredNode<Group>(); 
    106108    NodeRefPtr       n1N    = makeCoredNode<Group>(); 
     
    141143        SLOG << " === threadFunc0: modify loop start [" << loopCount << "]" << endLog; 
    142144     
    143         SLOG << "threadFunc0: modify loop [" << loopCount << "]: pre barrier 1" << endLog; 
    144145        gSyncBarrier->enter(2); 
    145146         
    146147        // wait for other threads to sync their aspects 
    147148         
    148         SLOG << "threadFunc0: modify loop [" << loopCount << "]: pre barrier 2" << endLog; 
    149         gSyncBarrier->enter(2); 
    150          
    151         SLOG << "threadFunc0: modify loop [" << loopCount << "]: 'modify' scene" << endLog; 
    152          
     149        if(gExitFlag == true) 
     150            exitFlag = true;        // set the local exit flag 
     151         
     152        gSyncBarrier->enter(2); 
     153         
     154        if(exitFlag == true) 
     155            break;              
     156           
    153157        Thread::getCurrentChangeList()->clear(); 
    154158         
     
    158162        case 0: 
    159163        { 
    160             SLOG << "threadFunc0 modify loop [" << loopCount << "]: changing trans" << endLog; 
    161              
    162164            trans->editMatrix().setTranslate( 
    163165                Vec3f(osgRand(), osgRand(), osgRand())); 
     
    168170        case 1: 
    169171        { 
    170             SLOG << "threadFunc0 modify loop [" << loopCount << "]: child transN -> groupN" << endLog; 
    171          
    172172            NodeRefPtr moveChild; 
    173173             
     
    182182        case 2: 
    183183        { 
    184             SLOG << "threadFunc0 modify loop [" << loopCount << "]: child groupN -> transN" << endLog; 
    185          
    186184            NodeRefPtr moveChild; 
    187185         
     
    197195        commitChanges(); 
    198196    } 
    199     while(!exitFlag); // only this thread detects exit requests 
     197    while(true); 
    200198         
    201199    SLOG << "threadFunc0: STOP" << endLog; 
     
    206204    TreePrinter tp(std::cerr); 
    207205 
     206    bool exitFlag = false; 
     207     
    208208    SLOG << "threadFunc1: START" << endLog; 
    209209 
     
    216216        SLOG << " === threadFunc1: render loop start [" << loopCount << "]" << endLog; 
    217217     
    218         SLOG << "threadFunc1: render loop [" << loopCount << "]: pre barrier 1" << endLog; 
    219         gSyncBarrier->enter(2); 
    220          
    221         SLOG << "threadFunc1: render loop [" << loopCount << "]: pre  SYNC scene" << endLog; 
     218        gSyncBarrier->enter(2); 
     219         
    222220         
    223221        gThread0->getChangeList()->applyNoClear(); 
    224222         
    225         SLOG << "threadFunc1: render loop [" << loopCount << "]: post SYNC scene" << endLog; 
    226          
    227         SLOG << "threadFunc1: render loop [" << loopCount << "]: pre barrier 2" << endLog; 
    228         gSyncBarrier->enter(2); 
    229          
    230         SLOG << "threadFunc1: render loop [" << loopCount << "]: 'render' scene" << endLog; 
     223        if(gExitFlag == true) 
     224            exitFlag = true;        // set the local exit flag 
     225             
     226        gSyncBarrier->enter(2); 
     227         
     228        if(exitFlag == true) 
     229            break; 
    231230         
    232231        traverse(gRootN, boost::bind(&TreePrinter::enterFunc, &tp, _1    ), 
     
    235234        ++loopCount; 
    236235    } 
    237     while(true); // this thread runs forever 
     236    while(true); 
    238237     
    239238    SLOG << "threadFunc1: STOP" << endLog; 
     
    254253    osgSleep(1000); 
    255254     
    256     exitFlag = true;        // signal thread0 to exit 
    257     Thread::join(gThread0); // wait for thread0 
    258      
    259     gThread1->terminate();  // signal thread1 to exit 
     255    gExitFlag = true;        // signal threads to exit 
     256     
     257    Thread::join(gThread0); // wait for threads 
     258    Thread::join(gThread1); 
    260259     
    261260    osgExit();