samedi 12 octobre 2019

Does random_device start at a different state for each thread?

Is it guaranteed that random_device won't start at the same internal state for each new thread? So that the following code is likely to give two distinct values?

#include <iostream>
#include <random>
#include <thread>
#include <mutex>

using namespace std;

int main()
{
    auto thr = []()
    {
        static mutex mtx;
        mtx.lock();
        cout << random_device()() << " " << endl;
        mtx.unlock();
    };
    thread t1( thr );
    thread t2( thr );
    t1.join();
    t2.join();
}



Aucun commentaire:

Enregistrer un commentaire