C++11 thread 生成随机数的方法

来源:互联网 发布:mac 装了office2016卡 编辑:程序博客网 时间:2024/06/06 04:04


#include<stdio.h>#include<stdlib.h>#include<string.h>#include<thread>#include<iostream>#include<atomic>#include<mutex>#include<time.h>using namespace std;mutex m;time_t t;void test(int seed,int depth,clock_t _time) {srand(_time + seed);m.lock();cout << rand() << endl;m.unlock();if (depth-->0) {test(seed, depth, time(&t) +rand());}}int main(){thread t1(test,12012,100,time(&t));thread t2(test,25301,100, time(&t));t1.join();t2.join();return 0;}

0 0
原创粉丝点击