Changeset 7470

Show
Ignore:
Timestamp:
09/25/07 11:45:44
Author:
robert
Message:

Changed the startThread synchronozation so that is uses a Block to hold the
thread starting the new thread back until the new thread is properly running.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenThreads/trunk/include/OpenThreads/Thread

    r7461 r7470  
    374374    void * _prvData; 
    375375     
    376     Mutex _prvDataMutex; 
    377      
    378376    /** 
    379377     *  Master thread's priority, set by Thread::Init. 
  • OpenThreads/trunk/src/OpenThreads/pthreads/PThread.c++

    r7461 r7470  
    3939 
    4040#include <OpenThreads/Thread> 
    41 #include <OpenThreads/ScopedLock> 
    4241#include "PThreadPrivateData.h" 
    4342 
     
    111110 
    112111        Thread *thread = static_cast<Thread *>(data); 
    113          
    114         ScopedLock<Mutex> lock(thread->_prvDataMutex); 
    115          
     112 
    116113        PThreadPrivateData *pd = 
    117114            static_cast<PThreadPrivateData *>(thread->_prvData); 
    118115             
    119         if (thread->_prvData==0) return 0; 
    120116 
    121117        if (pd->cpunum>=0) 
     
    164160 
    165161        pd->isRunning = true; 
     162 
     163        // release the thread that created this thread. 
     164        pd->threadStartedBlock.release(); 
     165 
    166166        thread->run(); 
     167 
    167168        pd->isRunning = false; 
    168169 
     
    398399Thread::~Thread() 
    399400{ 
    400     ScopedLock<Mutex> lock(_prvDataMutex);  
    401  
    402401    PThreadPrivateData *pd = static_cast<PThreadPrivateData *>(_prvData); 
    403402 
     
    415414     
    416415    _prvData = 0; 
    417  
    418416} 
    419417 
     
    631629    } 
    632630 
     631    pd->threadStartedBlock.reset(); 
     632 
    633633    status = pthread_create(&(pd->tid), &thread_attr, 
    634634                           ThreadPrivateActions::StartThread, 
    635635                           static_cast<void *>(this)); 
     636                            
     637    // wait till the thread has actually started. 
     638    pd->threadStartedBlock.block(); 
    636639 
    637640    if(status != 0) { 
     
    653656int Thread::startThread() 
    654657{ 
    655     ScopedLock<Mutex> lock(_prvDataMutex); 
    656658    if (_prvData) return start();  
    657659    else return 0; 
  • OpenThreads/trunk/src/OpenThreads/pthreads/PThreadPrivateData.h

    r6584 r7470  
    2222#include <pthread.h> 
    2323#include <OpenThreads/Thread> 
     24#include <OpenThreads/Block> 
    2425 
    2526namespace OpenThreads { 
     
    5051    volatile bool isRunning; 
    5152 
     53    Block threadStartedBlock; 
     54 
    5255    volatile bool isCanceled; 
    5356 
     
    6366 
    6467    volatile int cpunum; 
     68     
    6569 
    6670    static int nextId; 
  • OpenThreads/trunk/src/OpenThreads/sproc/SprocThread.c++

    r7468 r7470  
    2828#include <list> 
    2929#include <OpenThreads/Thread> 
    30 #include <OpenThreads/ScopedLock> 
    3130#include "SprocMutexPrivateData.h" 
    3231#include "SprocThreadPrivateData.h" 
     
    134133    Thread *thread = static_cast<Thread *>(data); 
    135134 
    136     ScopedLock<Mutex> lock(thread->_prvDataMutex); 
    137  
    138135    if (thread->_prvData==0) return; 
    139136 
     
    161158 
    162159    pd->isRunning = true; 
     160     
     161    // release the thread that created this thread. 
     162    pd->threadStartedBlock.release(); 
     163     
    163164    thread->run(); 
     165 
    164166    pd->isRunning = false; 
    165167 
     
    362364Thread::~Thread() 
    363365{ 
    364     ScopedLock<Mutex> lock(_prvDataMutex);  
    365  
    366366    DPRINTF(("(SPROC THREAD) %s:%d, In OpenThreads::Thread destructor\n", 
    367367        __FILE__, __LINE__)); 
     
    486486        static_cast<SprocThreadPrivateData *> (_prvData); 
    487487 
     488    pd->threadStartedBlock.reset(); 
     489 
    488490    int pid = sproc(ThreadPrivateActions::StartThread, 
    489491                    PR_SALL, 
     
    504506    pd->pid = pid; 
    505507    pd->idSet = true; 
     508 
     509    // wait till the thread has actually started. 
     510    pd->threadStartedBlock.block(); 
     511 
    506512    return 0; 
    507513 
     
    516522int Thread::startThread() 
    517523{ 
    518     ScopedLock<Mutex> lock(_prvDataMutex); 
    519524    if (_prvData) return start();  
    520525    else return 0; 
  • OpenThreads/trunk/src/OpenThreads/sproc/SprocThreadPrivateData.h

    r6584 r7470  
    2525 
    2626#include <OpenThreads/Thread> 
     27#include <OpenThreads/Block> 
    2728#include "SprocThreadPrivateActions.h" 
    2829 
     
    5354    volatile bool isRunning; 
    5455 
     56    Block threadStartedBlock; 
     57 
    5558    volatile bool isCanceled; 
    5659 
  • OpenThreads/trunk/src/OpenThreads/win32/Win32Thread.cpp

    r7468 r7470  
    2121#include <process.h> 
    2222 
    23 #include <OpenThreads/ScopedLock> 
    24  
    2523#if defined(_MSC_VER) && (_MSC_VER < 1300) 
    2624#ifdef __SGI_STL 
     
    9593            Thread *thread = static_cast<Thread *>(data); 
    9694         
    97             ScopedLock<Mutex> lock(thread->_prvDataMutex); 
    98  
    9995            Win32ThreadPrivateData *pd = 
    10096                static_cast<Win32ThreadPrivateData *>(thread->_prvData); 
     
    109105 
    110106            pd->isRunning = true; 
     107             
     108            // release the thread that created this thread. 
     109            pd->threadStartedBlock.release(); 
    111110 
    112111            try{ 
     
    262261Thread::~Thread() 
    263262{ 
    264     ScopedLock<Mutex> lock(_prvDataMutex);  
    265  
    266263    Win32ThreadPrivateData *pd = static_cast<Win32ThreadPrivateData *>(_prvData); 
    267264 
     
    336333    // pd->stackSizeLocked = true; 
    337334    unsigned int ID; 
     335     
     336    pd->threadStartedBlock.reset(); 
    338337 
    339338    pd->tid.set( (void*)_beginthreadex(NULL,pd->stackSize,ThreadPrivateActions::StartThread,static_cast<void *>(this),0,&ID)); 
    340339 
    341340    pd->uniqueId = (int)ID; 
     341 
     342    // wait till the thread has actually started. 
     343    pd->threadStartedBlock.block(); 
    342344 
    343345    if(!pd->tid) { 
     
    351353int Thread::startThread() 
    352354{ 
    353     ScopedLock<Mutex> lock(_prvDataMutex); 
    354355    if (_prvData) return start();  
    355356    else return 0; 
  • OpenThreads/trunk/src/OpenThreads/win32/Win32ThreadPrivateData.h

    r6584 r7470  
    2525 
    2626#include <OpenThreads/Thread> 
     27#include <OpenThreads/Block> 
    2728#include "HandleHolder.h" 
    2829 
     
    4849    bool isRunning; 
    4950 
    50         int  cancelMode; // 0 - deffered (default) 1-asynch 2-disabled   
     51    Block threadStartedBlock; 
     52 
     53    int  cancelMode; // 0 - deffered (default) 1-asynch 2-disabled   
    5154 
    5255    bool detached;