Changeset 2833
- Timestamp:
- Sep 14, 2012, 9:42:09 AM (11 years ago)
- Location:
- branches/0.9-stable/yat/random
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9-stable/yat/random/random.cc
r2804 r2833 24 24 #include "yat/statistics/Histogram.h" 25 25 #include "yat/utility/Exception.h" 26 27 #include <boost/thread/locks.hpp> 26 28 27 29 #include <cassert> … … 93 95 if (!rng) 94 96 throw utility::GSL_error("RNG failed to allocate memory"); 97 boost::unique_lock<boost::mutex> lock(mutex_); 95 98 gsl_rng_set(rng, seed_); 96 99 // bump seed to avoid subsequent gsl_rng to be identical … … 98 101 // rng_ owns rng and takes care of deallocation 99 102 rng_.reset(rng); 100 } 103 } // lock is released here 101 104 102 105 103 106 void RNG::seed(unsigned long s) const 104 107 { 108 boost::unique_lock<boost::mutex> lock(mutex_); 105 109 gsl_rng_set(rng(),s); 106 110 seed_ = s+1; 107 } 111 } // lock is released here 108 112 109 113 -
branches/0.9-stable/yat/random/random.h
r2804 r2833 28 28 29 29 #include <boost/concept_check.hpp> 30 #include <boost/thread.hpp> 30 31 #include <boost/thread/tss.hpp> 31 32 … … 193 194 mutable boost::thread_specific_ptr<gsl_rng> rng_; 194 195 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_; 195 198 }; 196 199
Note: See TracChangeset
for help on using the changeset viewer.