Changeset 421 for experimental/Threading
- Timestamp:
- Oct 20, 2012, 1:07:25 AM (12 years ago)
- Location:
- experimental/Threading/Threading
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/Threading/Threading/ChannelWorker.cpp
r420 r421 3 3 4 4 5 ChannelWorker::ChannelWorker( int numThreads, OpenThreads::Barrier& syncBarrier)6 : _ numThreads(numThreads), _syncBarrier(syncBarrier), _done(false)5 ChannelWorker::ChannelWorker() 6 : _done(false) 7 7 { 8 8 OSG_ALWAYS<<"ChannelWorker instantiated."<<std::endl; … … 28 28 29 29 } while (!testCancel() && !_done); // repeat as long it is canceld or set as Done 30 31 32 //_syncBarrier.block(_numThreads); // Sync the threads.33 34 30 } 35 31 … … 54 50 // commenting out debug info as it was cashing crash on exit, presumable 55 51 // 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; 57 53 OpenThreads::Thread::YieldCurrentThread(); 58 54 } -
experimental/Threading/Threading/ChannelWorker.h
r420 r421 3 3 #include <osg/Referenced> 4 4 #include <OpenThreads/Thread> 5 #include <OpenThreads/Barrier>6 5 7 6 … … 9 8 { 10 9 public: 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. 13 12 virtual void run(); 14 13 virtual int cancel(); 15 14 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; } 18 17 19 18 private: 20 int _numThreads;21 19 bool _done; 22 OpenThreads::Barrier& _syncBarrier;23 20 }; -
experimental/Threading/Threading/SimHost.cpp
r420 r421 25 25 SimHost::~SimHost() 26 26 { 27 _channelWorker.clear();27 //_channelWorker.clear(); 28 28 } 29 29 … … 37 37 for(int i=0; i<numThreads-1; ++i) 38 38 { 39 osg::ref_ptr<ChannelWorker> worker = new ChannelWorker( numThreads, syncBarrier);39 osg::ref_ptr<ChannelWorker> worker = new ChannelWorker(); 40 40 _channelWorker.push_back(worker); 41 41 } … … 58 58 { 59 59 int status; 60 61 //thread->addObserver(&observer); 60 62 61 //thread->setStackSize(1024*256); 63 62 status = _channelWorker[i]->start(); … … 72 71 for(int i=0;i<static_cast<int>(_channelWorker.size());++i) 73 72 { 74 _channelWorker[i]->setDone(true);75 //_channelWorker[i]->cancel(); // Seems to be wrong73 //_channelWorker[i]->setDone(true); // non blocking 74 _channelWorker[i]->cancel(); // Blocking 76 75 } 76 77 for(int i=0;i<100000000;i++) 78 OSG_ALWAYS<<""; 77 79 78 80 //syncBarrier.block(numThreads); // Block until all threads are ready
Note: See TracChangeset
for help on using the changeset viewer.