
On Thu, Dec 20, 2012 at 8:26 AM, Philipp Kraus
Hello,
I'm using boost::random_device & boost::mt19937 for creating random numbers. I would like to use both within different threads, are both object thread-safe, so I can use it without any thread locking?
Thanks
Phil
I doubt they are thread safe due to the performance overhead involved in making them thread safe. Having written and used other MT-based RNGs, it could probably double the cost of generating random numbers, even in cases where thread safety is not required. If possible, can you construct an object per thread? This is typically the way that I have used these wrappers (and actually the reason for writing them). If you need a specific sequence, it might make sense to generate many random numbers up-front, and then use them in the thread. If all else fails, you can use your own boost::mutex and boost::lock_guard to ensure thread safety. Brian