void MonteCarloRun::run()
{
    boost::timer::nanosecond_type _timeSinceLast = _timer.elapsed().wall;
    double period = 1 / _rate;

    while(_isRunning)
    {
        boost::this_thread::sleep_for(boost::chrono::microseconds((long)(period * 1e6 * _N)));
        if(checkBuffer((_N + _frameSize)))
        {
            _dataStream->changeFunc(genStreamFunc());
            clearBuffer();
        }

        if(_timePerScheme < _timer.elapsed().wall - _timeSinceLast)
        {
            getNextMod();

            boost::shared_lock<boost::shared_mutex> modLock(*_modType->getMutex());
            AMC::ModType tempModType = _modType->getData();
            modLock.unlock();

            if(tempModType != AMC::ModType::MODTYPE_NR_ITEMS)
            {
                std::cout << "Setting modulation scheme to: " << AMC::toString(tempModType) << std::endl;
                _featureExtractor->stop();

                _dataStream->changeFunc(genStreamFunc());
                clearBuffer();

                _featureExtractor->start(AMC::FeatureExtractor::WRITE_TO_FILE, tempModType);

                _timeSinceLast = _timer.elapsed().wall;
            }
            else
            {
                _isRunning = false;
                std::cout << "Finished..." << std::endl;

                _dataStream->stopStream();
                _featureExtractor->stop();
            }
        }
    }
}
void MonteCarloRun::start()
{
    _dataStream->changeFunc(genStreamFunc());
    std::cout << "Setting modulation scheme to: " << AMC::toString(_modType) << std::endl;

    _dataStream->startStream();
    _featureExtractor->start(AMC::FeatureExtractor::WRITE_TO_FILE, _modType);

    _isRunning = true;
    _thread = boost::thread(&MonteCarloRun::run, this);
}
void MonteCarloRun::start()
{
    _dataStream->changeFunc(genStreamFunc());

    // Lock the mod type mutex.
    boost::shared_lock<boost::shared_mutex> modTypeLock(*_modType->getMutex());

    std::cout << "Setting modulation scheme to: " << AMC::toString(_modType->getData()) << std::endl;
    _dataStream->startStream();
    _featureExtractor->start(AMC::FeatureExtractor::WRITE_TO_FILE, _modType->getData());

    modTypeLock.unlock();

    _isRunning = true;
    _thread = boost::thread(&MonteCarloRun::run, this);
}