#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; }
C++11 thread 生成随机数的方法
最新推荐文章于 2023-12-25 15:14:10 发布