Changeset 2833


Ignore:
Timestamp:
Sep 14, 2012, 9:42:09 AM (11 years ago)
Author:
Peter
Message:

fixes #720

Location:
branches/0.9-stable/yat/random
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/0.9-stable/yat/random/random.cc

    r2804 r2833  
    2424#include "yat/statistics/Histogram.h"
    2525#include "yat/utility/Exception.h"
     26
     27#include <boost/thread/locks.hpp>
    2628
    2729#include <cassert>
     
    9395    if (!rng)
    9496      throw utility::GSL_error("RNG failed to allocate memory");
     97    boost::unique_lock<boost::mutex> lock(mutex_);
    9598    gsl_rng_set(rng, seed_);
    9699    // bump seed to avoid subsequent gsl_rng to be identical
     
    98101    // rng_ owns rng and takes care of deallocation
    99102    rng_.reset(rng);
    100   }
     103  } // lock is released here
    101104
    102105
    103106  void RNG::seed(unsigned long s) const
    104107  {
     108    boost::unique_lock<boost::mutex> lock(mutex_);
    105109    gsl_rng_set(rng(),s);
    106110    seed_ = s+1;
    107   }
     111  } // lock is released here
    108112
    109113
  • branches/0.9-stable/yat/random/random.h

    r2804 r2833  
    2828
    2929#include <boost/concept_check.hpp>
     30#include <boost/thread.hpp>
    3031#include <boost/thread/tss.hpp>
    3132
     
    193194    mutable boost::thread_specific_ptr<gsl_rng> rng_;
    194195    mutable unsigned long seed_;
     196    // guard needs to be mutable because major mission for it is to protect seed_ against multi-access, and seed_ is mutable...
     197    mutable boost::mutex mutex_;
    195198  };
    196199
Note: See TracChangeset for help on using the changeset viewer.