Changeset 430 for experimental/Threading


Ignore:
Timestamp:
Oct 25, 2012, 9:49:08 AM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/Threading/Threading
Files:
4 edited

Legend:

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

    r427 r430  
    55
    66
    7 IGConnector::IGConnector()
     7IGConnector::IGConnector(int numberOfchannels, OpenThreads::Barrier& frameBarrier)
     8: _numberOfchannels(numberOfchannels), _frameBarrier(frameBarrier)
    89{
    910        OSG_ALWAYS<<"IGConnector instantiated."<<std::endl;
     
    1617void IGConnector::operator()(ThreadedWorker* threadObject)
    1718{
    18         OSG_ALWAYS<<"IGConnector running: ID "<<threadObject->getThreadId()<<std::endl;
     19        OSG_ALWAYS<<"IGConnector "<<threadObject->getThreadId()<<" : Receiving SOF packet"<<std::endl;
     20
     21        _frameBarrier.block(_numberOfchannels+1);  // Sync the main and all IG threads.
     22
     23        OSG_ALWAYS<<"IGConnector "<<threadObject->getThreadId()<<" : Sending SOF answer packet"<<std::endl;
    1924
    2025        // Place Holder
  • experimental/Threading/Threading/IGConnector.h

    r425 r430  
    11#pragma once
    22#include "ThreadWorkerBase.h"
     3#include <OpenThreads/Barrier>
    34
    45class IGConnector :     public ThreadWorkerBase
    56{
    67public:
    7         IGConnector();
     8        IGConnector(int numberOfchannels, OpenThreads::Barrier& frameBarrier);
    89        ~IGConnector();
    910
    1011        void operator() (ThreadedWorker* threadObject);
     12
     13private:
     14        int _numberOfchannels;
     15        OpenThreads::Barrier& _frameBarrier;
    1116};
  • experimental/Threading/Threading/SimHost.cpp

    r426 r430  
    33
    44#include <OpenThreads/Thread>
    5 #include <OpenThreads/Barrier>
    65
    76// System includes
     
    2120{
    2221        OSG_ALWAYS<<"SimHost instantiated."<<std::endl;
     22        numberofChannels = 6;
    2323}
    2424
     
    3030void SimHost::initialize()
    3131{
    32         int numThreads = 6+1;   // 6 channels and one main thread
     32        done = false;
     33        int numThreads = numberofChannels+1;    // #channels + one main thread
    3334        OpenThreads::Barrier syncBarrier;
    3435
    3536        // Create IG Connectors
    3637        OSG_ALWAYS<<"Creating IG Connectors..."<<std::endl;
    37         for(int i=0; i<numThreads-1; ++i)
     38        for(int i=0; i<numberofChannels; ++i)
    3839        {
    3940                osg::ref_ptr<ThreadedWorker> threadObject = new ThreadedWorker();
    40                 osg::ref_ptr<IGConnector> IGCon = new IGConnector();
     41                osg::ref_ptr<IGConnector> IGCon = new IGConnector(numberofChannels, _frameBarrier);
    4142                threadObject->setThreadWorker(IGCon);
    4243                _threadObjects.push_back(threadObject);
     
    6768        }
    6869
    69         // Do something in the main thread
    70                 for(int i=0;i<10000000;i++)     OSG_ALWAYS<<"";
     70        // Enter the SimHost main loop
     71        while(!done)
     72        {
     73                // Wait until all Channels have sent an SOF packet
     74                _frameBarrier.block(numberofChannels+1);  // Sync the main and all IG threads.
     75                OSG_ALWAYS<<"All IGConnectors have recieved a SOF packet: Starting new Frame"<<std::endl;
     76        }
    7177       
    7278        // Signal threads to finish
     
    7682                _threadObjects[i]->cancel();    // Blocking
    7783        }
    78 
    79         /*for(int i=0;i<100000000;i++)
    80                 OSG_ALWAYS<<"";*/
    81 
    8284}
  • experimental/Threading/Threading/SimHost.h

    r425 r430  
    44#include <osg/Referenced>
    55#include <osg/ref_ptr>
     6#include <OpenThreads/Barrier>
    67
    78#include "ThreadedWorker.h"
     
    1920
    2021private:
     22        bool done;
     23        int numberofChannels;
     24        OpenThreads::Barrier _frameBarrier;
    2125        std::vector<osg::ref_ptr<IGConnector> > _IGConnectors;
    2226        std::vector<osg::ref_ptr<ThreadedWorker> > _threadObjects;
Note: See TracChangeset for help on using the changeset viewer.