Changeset 421 for experimental/Threading


Ignore:
Timestamp:
Oct 20, 2012, 1:07:25 AM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/Threading/Threading
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • experimental/Threading/Threading/ChannelWorker.cpp

    r420 r421  
    33
    44
    5 ChannelWorker::ChannelWorker(int numThreads, OpenThreads::Barrier& syncBarrier)
    6  : _numThreads(numThreads), _syncBarrier(syncBarrier), _done(false)
     5ChannelWorker::ChannelWorker()
     6 : _done(false)
    77{
    88        OSG_ALWAYS<<"ChannelWorker instantiated."<<std::endl;
     
    2828
    2929        } while (!testCancel() && !_done);      // repeat as long it is canceld or set as Done
    30 
    31 
    32         //_syncBarrier.block(_numThreads);  // Sync the threads.
    33 
    3430}
    3531
     
    5450            // commenting out debug info as it was cashing crash on exit, presumable
    5551            // due to OSG_NOTIFY or std::cout destructing earlier than this destructor.
    56             OSG_ALWAYS<<"   Waiting for ChannelWorker to cancel "<<this<<std::endl;
     52            //OSG_ALWAYS<<"   Waiting for ChannelWorker to cancel "<<this<<std::endl;
    5753            OpenThreads::Thread::YieldCurrentThread();
    5854        }
  • experimental/Threading/Threading/ChannelWorker.h

    r420 r421  
    33#include <osg/Referenced>
    44#include <OpenThreads/Thread>
    5 #include <OpenThreads/Barrier>
    65
    76
     
    98{
    109public:
    11         ChannelWorker(int numThreads, OpenThreads::Barrier& syncBarrier) ;
    12         ~ChannelWorker();
     10        ChannelWorker() ;
     11        ~ChannelWorker();       //Destroying the thread object will implicit call cancel(), then the function will block until the thread has finished.
    1312        virtual void run();
    1413        virtual int cancel();
    1514       
    16         void setDone(bool done);
    17         bool getDone() const { return _done; }
     15        void setDone(bool done);        // sinbgals the thread to stop but returns immediately. Use cancel if you want to wait blocking until the thread is canceled.
     16        bool getDone() const { return _done; } 
    1817
    1918private:
    20         int _numThreads;
    2119        bool _done;
    22         OpenThreads::Barrier& _syncBarrier;
    2320};
  • experimental/Threading/Threading/SimHost.cpp

    r420 r421  
    2525SimHost::~SimHost()
    2626{
    27         _channelWorker.clear();
     27        //_channelWorker.clear();
    2828}
    2929
     
    3737        for(int i=0; i<numThreads-1; ++i)
    3838        {
    39                 osg::ref_ptr<ChannelWorker> worker = new ChannelWorker(numThreads, syncBarrier);
     39                osg::ref_ptr<ChannelWorker> worker = new ChannelWorker();
    4040                _channelWorker.push_back(worker);
    4141        }
     
    5858        {
    5959                int status;
    60                        
    61                 //thread->addObserver(&observer);
     60               
    6261                //thread->setStackSize(1024*256);
    6362                status = _channelWorker[i]->start();
     
    7271    for(int i=0;i<static_cast<int>(_channelWorker.size());++i)
    7372        {
    74                 _channelWorker[i]->setDone(true);
    75                 //_channelWorker[i]->cancel();          // Seems to be wrong
     73                //_channelWorker[i]->setDone(true);     // non blocking
     74                _channelWorker[i]->cancel();    // Blocking
    7675        }
     76
     77        for(int i=0;i<100000000;i++)
     78                OSG_ALWAYS<<"";
    7779
    7880        //syncBarrier.block(numThreads);  // Block until all threads are ready
Note: See TracChangeset for help on using the changeset viewer.