From 2b194509ae3246e47e0bf6f3597830332a176e76 Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Wed, 25 Sep 2024 00:58:22 +0800 Subject: [PATCH] Add photon::rand32() and photon::rand64() --- common/memory-stream/memory-stream.cpp | 4 +-- common/memory-stream/test/test.cpp | 2 +- common/metric-meter/test/example.cpp | 2 +- common/test/perf_rcuptr.cpp | 4 +-- common/test/test.cpp | 2 +- common/test/test_throttle.cpp | 8 ++--- common/utility.cpp | 26 ++++++++++++++++ common/utility.h | 16 ++++++++++ examples/rpc/client_main.cpp | 3 +- fs/test/test.cpp | 21 ++++++------- io/test/test-iouring.cpp | 1 - io/test/test-syncio.cpp | 4 +-- net/http/test/client_function_test.cpp | 3 +- net/http/test/headers_test.cpp | 4 +-- net/http/test/server_function_test.cpp | 4 +-- rpc/test/test-ooo.cpp | 6 ++-- thread/test/test-pool.cpp | 2 +- thread/test/test-thread.cpp | 43 ++++++++++++-------------- thread/thread.cpp | 2 +- 19 files changed, 94 insertions(+), 63 deletions(-) diff --git a/common/memory-stream/memory-stream.cpp b/common/memory-stream/memory-stream.cpp index aee8d395..a09451a4 100644 --- a/common/memory-stream/memory-stream.cpp +++ b/common/memory-stream/memory-stream.cpp @@ -134,7 +134,7 @@ class FaultStream : public IStream static inline bool gen() { - if (rand() % 100 < 1) + if (photon::rand32() % 100 < 1) { static const uint16_t e[] = { 1, 2, 83, 111, 112, @@ -163,7 +163,7 @@ class FaultStream : public IStream 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, }; - errno = e[rand() % LEN(e)]; + errno = e[photon::rand32() % LEN(e)]; return true; } return false; diff --git a/common/memory-stream/test/test.cpp b/common/memory-stream/test/test.cpp index 0e7912d7..61ed2757 100644 --- a/common/memory-stream/test/test.cpp +++ b/common/memory-stream/test/test.cpp @@ -40,7 +40,7 @@ void* stream_writer(void* stream_) auto p = STR; while(count > 0) { - size_t len = rand() % 8; + size_t len = photon::rand32() % 8; len = min(len, count); LOG_DEBUG("Begin write ", VALUE(len)); auto ret = s->write(p, len); diff --git a/common/metric-meter/test/example.cpp b/common/metric-meter/test/example.cpp index db310046..8c66ebbb 100644 --- a/common/metric-meter/test/example.cpp +++ b/common/metric-meter/test/example.cpp @@ -58,7 +58,7 @@ int main() { SCOPE_LATENCY(table.pread_latency); SCOPE_LATENCY(table.pread_max); table.maxv.put(photon::now % 10000000 / 1000000); - photon::thread_usleep(1000 + rand() % 1000); + photon::thread_usleep(1000 + photon::rand32() % 1000); } photon::thread_usleep(5000 * 1000); } diff --git a/common/test/perf_rcuptr.cpp b/common/test/perf_rcuptr.cpp index ea791564..c7d8998a 100644 --- a/common/test/perf_rcuptr.cpp +++ b/common/test/perf_rcuptr.cpp @@ -37,7 +37,7 @@ int main() { for (int i = 0; i < 100; i++) { photon::thread_create11([&cntr, &ptr, &sem]() { for (int j = 0; j < 1000; j++) { - auto x = rand() % 10; + auto x = photon::rand32() % 10; if (x) { // 99% reader // ptr.read_lock(); auto x = ptr->val; @@ -92,7 +92,7 @@ int main() { for (int i = 0; i < 100; i++) { photon::thread_create11([&cntr, &ptr, &sem, &rwlock]() { for (int j = 0; j < 1000; j++) { - auto x = rand() % 10; + auto x = photon::rand32() % 10; if (x) { // 90% reader photon::scoped_rwlock _(rwlock, photon::RLOCK); (void)ptr.load()->val; diff --git a/common/test/test.cpp b/common/test/test.cpp index 8e11c380..d0af0733 100644 --- a/common/test/test.cpp +++ b/common/test/test.cpp @@ -256,7 +256,7 @@ TEST(Callback, virtual_function) for (int i=0; i<100; ++i) { - int x = rand(); + int x = photon::rand32(); EXPECT_EQ(ca(x), RET + x); EXPECT_EQ(cb(x), RET - x); EXPECT_EQ(cc(x), RET + x*2); diff --git a/common/test/test_throttle.cpp b/common/test/test_throttle.cpp index 9b5352d9..7c3be612 100644 --- a/common/test/test_throttle.cpp +++ b/common/test/test_throttle.cpp @@ -16,7 +16,7 @@ TEST(Throttle, basic) { auto start = std::chrono::steady_clock::now(); while (total) { // assume each step may consume about 4K ~ 1M - auto step = rand() % (1UL * 1024 * 1024 - 4096) + 4096; + auto step = photon::rand32() % (1UL * 1024 * 1024 - 4096) + 4096; if (step > total) step = total; total -= step; } @@ -36,7 +36,7 @@ TEST(Throttle, basic) { start = std::chrono::steady_clock::now(); while (total) { // assume each step may consume about 4K ~ 1M - auto step = rand() % (1UL * 1024 * 1024 - 4096) + 4096; + auto step = photon::rand32() % (1UL * 1024 * 1024 - 4096) + 4096; if (step > total) step = total; t.consume(step); total -= step; @@ -61,11 +61,11 @@ TEST(Throttle, restore) { auto start = std::chrono::steady_clock::now(); while (total) { // assume each step may consume about 4K ~ 1M - auto step = rand() % (1UL * 1024 * 1024 - 4096) + 4096; + auto step = photon::rand32() % (1UL * 1024 * 1024 - 4096) + 4096; if (step > total) step = total; submit += step; t.consume(step); - if (rand() % 2) { + if (photon::rand32() % 2) { // 1 of 2 chance to fail and restore consumed chance t.restore(step); restore += step; diff --git a/common/utility.cpp b/common/utility.cpp index 644487a4..19f9e356 100644 --- a/common/utility.cpp +++ b/common/utility.cpp @@ -16,6 +16,7 @@ limitations under the License. #include #include +#include #include "utility.h" #include "estring.h" #include "alog.h" @@ -70,3 +71,28 @@ void print_stacktrace() { free(stacktrace); } +namespace photon { + +static std::random_device rd; +thread_local std::mt19937 gen32(rd()); +thread_local std::mt19937_64 gen64(rd()); + +uint32_t rand32() { + return gen32(); +} + +uint32_t rand32_distribution(uint32_t min, uint32_t max) { + std::uniform_int_distribution dist(min, max); + return dist(gen32); +} + +uint64_t rand64() { + return gen64(); +} + +uint64_t rand64_distribution(uint64_t min, uint64_t max) { + std::uniform_int_distribution dist(min, max); + return dist(gen64); +} + +} \ No newline at end of file diff --git a/common/utility.h b/common/utility.h index 02196bac..2c6c06cb 100644 --- a/common/utility.h +++ b/common/utility.h @@ -309,6 +309,22 @@ uint64_t sat_sub(uint64_t x, uint64_t y) { return c ? 0 : z; } +// Generate random number in [0, UINT32_MAX] +// The random engine is std::mt19937, which is even faster then rand() in C lib +uint32_t rand32(); + +// Generate random number, uniformly distributed on the closed interval [min, max] +// Equals to rand32() % (max - min + 1) + min, but slower than it +uint32_t rand32_distribution(uint32_t min, uint32_t max); + +// Generate random number in [0, UINT64_MAX] +// The random engine is std::mt19937, which is even faster then rand() in C lib +uint64_t rand64(); + +// Generate random number, uniformly distributed on the closed interval [min, max] +// Equals to rand64() % (max - min + 1) + min, but slower than it +uint64_t rand64_distribution(uint64_t min, uint64_t max); + } diff --git a/examples/rpc/client_main.cpp b/examples/rpc/client_main.cpp index 7a1a4339..78ec40e8 100644 --- a/examples/rpc/client_main.cpp +++ b/examples/rpc/client_main.cpp @@ -52,7 +52,7 @@ void run_some_task(ExampleClient* client) { IOVector iov; char writebuf[] = "write data like pwrite"; iov.push_back(writebuf, sizeof(writebuf)); - auto tmpfile = "/tmp/test_file_" + std::to_string(rand()); + auto tmpfile = "/tmp/test_file_" + std::to_string(photon::rand32()); auto ret = client->RPCWrite(ep, tmpfile, iov.iovec(), iov.iovcnt()); LOG_INFO("Write to tmpfile ` ret=`", tmpfile, ret); @@ -73,7 +73,6 @@ void handle_term(int) { int main(int argc, char** argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); - srand(time(NULL)); photon::init(); DEFER(photon::fini()); diff --git a/fs/test/test.cpp b/fs/test/test.cpp index 02d73eeb..bd90553c 100644 --- a/fs/test/test.cpp +++ b/fs/test/test.cpp @@ -830,7 +830,7 @@ TEST(range_split, range_split_aligned_case) } TEST(range_split, random_test) { - uint64_t begin=rand(), length=rand(), interval=rand(); + uint64_t begin=photon::rand32(), length=photon::rand32(), interval=photon::rand32(); LOG_DEBUG("begin=", begin, " length=", length, " interval=", interval); fs::range_split split(begin, length, interval); EXPECT_EQ(split.begin, begin); @@ -870,9 +870,9 @@ TEST(range_split_power2, basic) { TEST(range_split_power2, random_test) { uint64_t offset, length, interval; - offset = rand(); - length = rand(); - auto interval_shift = rand()%32 + 1; + offset = photon::rand32(); + length = photon::rand32(); + auto interval_shift = photon::rand32()%32 + 1; interval = uint64_t(1) << interval_shift; fs::range_split_power2 split(offset, length, interval); EXPECT_EQ(offset, split.begin); @@ -939,7 +939,7 @@ std::unique_ptr random_block(uint64_t size) { std::unique_ptr buff(new char[size]); char * p = buff.get(); while (size--) { - *(p++) = rand() % UCHAR_MAX; + *(p++) = photon::rand32() % UCHAR_MAX; } return buff; } @@ -1199,7 +1199,7 @@ TEST(XFile, error_stiuation) { void fill_random_buff(char * buff, size_t length) { for (size_t i = 0; i< length; i++) { - buff[i] = rand() % UCHAR_MAX; + buff[i] = photon::rand32() % UCHAR_MAX; } } @@ -1210,8 +1210,8 @@ void pread_pwrite_test(IFile *target, IFile *standard) { char data[max_piece_length]; char buff[max_piece_length]; for (int i = 0;i < test_round; i++) { - off_t off = rand() % max_file_size / getpagesize() * getpagesize(); - size_t len = rand() % max_piece_length / getpagesize() * getpagesize(); + off_t off = photon::rand32() % max_file_size / getpagesize() * getpagesize(); + size_t len = photon::rand32() % max_piece_length / getpagesize() * getpagesize(); if (off+len > max_file_size) { continue; } @@ -1228,8 +1228,8 @@ void pread_pwrite_test(IFile *target, IFile *standard) { EXPECT_EQ(0, memcmp(data, buff, ret)); } for (int i = 0;i < test_round; i++) { - off_t off = rand() % max_file_size; - size_t len = rand() % max_piece_length; + off_t off = photon::rand32() % max_file_size; + size_t len = photon::rand32() % max_piece_length; if (off+len > max_file_size) { len = max_file_size - off; } @@ -1373,7 +1373,6 @@ TEST(Walker, basic) { } int main(int argc, char **argv){ - srand(time(nullptr)); ::testing::InitGoogleTest(&argc, argv); if (photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_NONE)) return -1; diff --git a/io/test/test-iouring.cpp b/io/test/test-iouring.cpp index 82df35ee..0ba63e01 100644 --- a/io/test/test-iouring.cpp +++ b/io/test/test-iouring.cpp @@ -615,7 +615,6 @@ TEST_F(event_engine, cascading_one_shot) { } int main(int argc, char** arg) { - srand(time(nullptr)); set_log_output_level(ALOG_INFO); testing::InitGoogleTest(&argc, arg); testing::FLAGS_gtest_break_on_failure = true; diff --git a/io/test/test-syncio.cpp b/io/test/test-syncio.cpp index 6b70eb3e..39ed65bf 100644 --- a/io/test/test-syncio.cpp +++ b/io/test/test-syncio.cpp @@ -51,7 +51,7 @@ void* rand_read(void* _args) for (size_t i = 0; i < args->n; ++i) { - off_t offset = rand() % length * alignment + args->start; + off_t offset = photon::rand32() % length * alignment + args->start; ssize_t ret; // LOG_DEBUG("rand_read round:`", i); if (i&1) @@ -89,7 +89,7 @@ void* rand_write(void* _args) for (size_t i = 0; i < args->n; ++i) { - off_t offset = rand() % length * alignment + args->start; + off_t offset = photon::rand32() % length * alignment + args->start; ssize_t ret; if (i&1) { diff --git a/net/http/test/client_function_test.cpp b/net/http/test/client_function_test.cpp index 70a55c7c..1932a337 100644 --- a/net/http/test/client_function_test.cpp +++ b/net/http/test/client_function_test.cpp @@ -318,7 +318,7 @@ int chunked_handler_pt(void*, ISocketStream* sock) { break; } auto max_seg = std::min(remain - 1024, 2 * 4 * 1024UL); - auto seg = 1024 + rand() % max_seg; + auto seg = 1024 + photon::rand32() % max_seg; chunked_send(offset, seg, sock); rec.push_back(seg); offset += seg; @@ -373,7 +373,6 @@ TEST(http_client, chunked) { for (auto &c : std_data) { c = '0' + ((++num) % 10); } - srand(time(0)); server->set_handler({nullptr, &chunked_handler_pt}); for (auto tmp = 0; tmp < 20; tmp++) { auto op_test = client->new_operation(Verb::GET, url); diff --git a/net/http/test/headers_test.cpp b/net/http/test/headers_test.cpp index 2fc85953..58d5e822 100644 --- a/net/http/test/headers_test.cpp +++ b/net/http/test/headers_test.cpp @@ -94,7 +94,7 @@ class test_stream : public net::SocketStreamBase { // assert(count > remain); // LOG_DEBUG(remain); if (remain > 200) { - auto len = rand() % 100 + 1; + auto len = photon::rand32() % 100 + 1; // cout << string(ptr, len); memcpy(buf, ptr, len); ptr += len; @@ -154,7 +154,6 @@ TEST(headers, resp_header) { char rand_buf[64 * 1024 - 1]; Response rand_header(rand_buf, sizeof(rand_buf)); - srand(time(0)); test_stream stream(2000); do { auto ret = rand_header.receive_bytes(&stream); @@ -174,7 +173,6 @@ TEST(headers, resp_header) { char exceed_buf[64 * 1024 - 1]; Response exceed_header(exceed_buf, sizeof(exceed_buf)); - srand(time(0)); test_stream exceed_stream(3000); do { auto ret = exceed_header.receive_bytes(&exceed_stream); diff --git a/net/http/test/server_function_test.cpp b/net/http/test/server_function_test.cpp index f741e30d..3f8db572 100644 --- a/net/http/test/server_function_test.cpp +++ b/net/http/test/server_function_test.cpp @@ -232,7 +232,7 @@ int chunked_handler_pt(void*, net::ISocketStream* sock) { break; } auto max_seg = std::min(remain - 1024, 2 * 4 * 1024UL); - auto seg = 1024 + rand() % max_seg; + auto seg = 1024 + photon::rand32() % max_seg; chunked_send(offset, seg, sock); rec.push_back(seg); offset += seg; @@ -271,7 +271,6 @@ TEST(http_server, proxy_handler_get) { for (auto &c : std_data) { c = '0' + ((++num) % 10); } - srand(time(0)); //------------start source server--------------- auto source_server = net::new_tcp_socket_server(); DEFER({ delete source_server; }); @@ -459,7 +458,6 @@ TEST(http_server, mux_handler) { for (auto &c : std_data) { c = '0' + ((++num) % 10); } - srand(time(0)); //------------start source server--------------- auto source_server = net::new_tcp_socket_server(); DEFER({ delete source_server; }); diff --git a/rpc/test/test-ooo.cpp b/rpc/test/test-ooo.cpp index 59428709..85ae6e85 100644 --- a/rpc/test/test-ooo.cpp +++ b/rpc/test/test-ooo.cpp @@ -187,7 +187,7 @@ TEST(OutOfOrder, heavy_test) { } inline int error_issue(void*, OutOfOrderContext* args) { - if ((rand()%2) == 0) { + if ((photon::rand32()%2) == 0) { return -1; } return heavy_issue(nullptr, args); @@ -196,7 +196,7 @@ inline int error_issue(void*, OutOfOrderContext* args) { inline int error_complete(void*, OutOfOrderContext* args) { while (processing_queue.empty()) { thread_yield_to(nullptr); } //waiting till something comming args->tag = processing_queue.front(); - if (rand()%2) + if (photon::rand32()%2) return -1; processing_queue.pop(); return 0; @@ -207,7 +207,7 @@ inline int error_process() { thread_yield_to(nullptr); shuffle(issue_list.begin(), issue_list.end()); auto val = issue_list.back(); - if (rand()%2) + if (photon::rand32()%2) val = UINT64_MAX; processing_queue.push(val); issue_list.pop_back(); diff --git a/thread/test/test-pool.cpp b/thread/test/test-pool.cpp index 8a394b16..99c7bf37 100644 --- a/thread/test/test-pool.cpp +++ b/thread/test/test-pool.cpp @@ -22,7 +22,7 @@ using namespace photon; void *func1(void *) { - thread_sleep(rand()%5); + thread_sleep(photon::rand32()%5); return nullptr; } diff --git a/thread/test/test-thread.cpp b/thread/test/test-thread.cpp index 20ce8f60..881f9dc2 100644 --- a/thread/test/test-thread.cpp +++ b/thread/test/test-thread.cpp @@ -42,9 +42,9 @@ thread_local semaphore aSem(4); void* asdf(void* arg) { LOG_DEBUG("Hello world, in photon thread-`! step 1", (uint64_t)arg); - photon::thread_usleep(rand() % 1000 + 1000*500); + photon::thread_usleep(photon::rand32() % 1000 + 1000*500); LOG_DEBUG("Hello world, in photon thread-`! step 2", (uint64_t)arg); - photon::thread_usleep(rand() % 1000 + 1000*500); + photon::thread_usleep(photon::rand32() % 1000 + 1000*500); LOG_DEBUG("Hello world, in photon thread-`! step 3", (uint64_t)arg); aSem.signal(1); return arg; @@ -176,8 +176,6 @@ TEST(Sleep, queue) //Sleep_queue_Test::TestBody const int heap_size = 1000000; const int rand_limit = 100000000; - auto seed = /* time(0); */10007; - srand(seed); SleepQueue sleepq; sleepq.q.reserve(heap_size); vector items; @@ -185,14 +183,14 @@ TEST(Sleep, queue) //Sleep_queue_Test::TestBody LOG_INFO("ITEMS WITH SAME VALUE."); for (int i = 0; i < heap_size; i++){ auto th = new photon::thread(); - th->ts_wakeup = 1000;/* rand() % 100000000 */; + th->ts_wakeup = 1000;/* photon::rand32() % 100000000 */; items.emplace_back(th); } sleepq_perf(sleepq, items); LOG_INFO("ITEMS WITH RANDOM VALUE."); for (auto th: items) - th->ts_wakeup = rand() % rand_limit; + th->ts_wakeup = photon::rand32() % rand_limit; sleepq_perf(sleepq, items); LOG_INFO("sleepq test done."); @@ -350,7 +348,7 @@ void test_thread_switch(uint64_t nth, uint64_t stack_size) uint64_t count = total / nth; for (uint64_t i = 0; i < nth - 2; ++i) - photon::thread_create(&thread_pong, (void*)(uint64_t)(rand() % 32), stack_size); + photon::thread_create(&thread_pong, (void*)(uint64_t)(photon::rand32() % 32), stack_size); for (uint64_t i = 0; i < count; ++i) thread_yield_fast(); @@ -739,7 +737,7 @@ TEST(RWLock, checklock) { rw_count = 0; writing = false; for (uint64_t i=0; i<100;i++) { - uint64_t arg = (i << 32) | (rand()%10 < 7 ? photon::RLOCK : photon::WLOCK); + uint64_t arg = (i << 32) | (photon::rand32()%10 < 7 ? photon::RLOCK : photon::WLOCK); handles.emplace_back( photon::thread_enable_join( photon::thread_create(&rwlocktest, (void*)arg) @@ -939,7 +937,7 @@ void test_smp_waitq_resumer(int n, smp_args* args) { for (int j = 0; j < n*n*n; ++j) { - ::usleep(rand()%1024 + 1024); + ::usleep(photon::rand32()%1024 + 1024); args->q.resume_one(); } } @@ -1027,7 +1025,7 @@ TEST(smp, rwlock) { DEFER(photon::vcpu_fini()); std::vector handles; for (uint64_t i=0; i<100;i++) { - uint64_t arg = (i << 32) | (rand()%10 < 7 ? photon::RLOCK : photon::WLOCK); + uint64_t arg = (i << 32) | (photon::rand32()%10 < 7 ? photon::RLOCK : photon::WLOCK); handles.emplace_back( photon::thread_enable_join( photon::thread_create(&smprwlocktest, (void*)arg) @@ -1064,7 +1062,7 @@ void* test_smp_cvar_recver(void* args_) args->recvd++; } if (args->senders == 0) break; - thread_usleep(rand() % 128); + thread_usleep(photon::rand32() % 128); } args->recvers--; return 0; @@ -1077,7 +1075,7 @@ void* test_smp_cvar_sender(void* args_) auto m = args->n * args->n; for (int i=0; icvar.notify_one(); if (th) args->sent++; else args->missed++; @@ -1086,7 +1084,7 @@ void* test_smp_cvar_sender(void* args_) // LOG_DEBUG("notify_all()ed to ` threads", n); args->sent += n; } - thread_usleep(rand() % 128); + thread_usleep(photon::rand32() % 128); } args->senders--; return 0; @@ -1101,7 +1099,7 @@ void* test_smp_cvar(void* args_) if (args->senders == 0) while(args->recvers > 0) { - thread_usleep(rand() % 128); + thread_usleep(photon::rand32() % 128); auto n = args->cvar.notify_all(); args->sent += n; } @@ -1134,7 +1132,7 @@ void* test_smp_semaphore(void* args_) for (int i=1; i<=m*m; ++i) { args->sem.wait(i); - thread_usleep(rand()%64 + i*32); + thread_usleep(photon::rand32()%64 + i*32); args->sem.signal(i+1); } return 0; @@ -1433,7 +1431,7 @@ struct member_function_bind { void func(void*, char) {} TEST(thread11, functor_trait) { - char x = rand(); + char x = photon::rand32(); auto lambda = [](){}; auto lambda2 = [x](char) {(void)x; }; auto lambda3 = [lambda, &x]()->int { lambda(); return (int)x; }; @@ -1630,8 +1628,8 @@ TEST(interrupt, mutex) { // lock first mtx.lock(); auto th = photon::CURRENT; - int reason = rand(); - while (reason == 0) reason = rand(); + int reason = photon::rand32(); + while (reason == 0) reason = photon::rand32(); photon::thread_create11([th, reason]() { // any errno except 0 is able to stop waiting photon::thread_interrupt(th, reason); @@ -1647,8 +1645,8 @@ TEST(interrupt, mutex) { TEST(interrupt, condition_variable) { photon::condition_variable cond; auto th = photon::CURRENT; - int reason = rand(); - while (reason == 0) reason = rand(); + int reason = photon::rand32(); + while (reason == 0) reason = photon::rand32(); photon::thread_create11([th, reason]() { // any errno except 0 is able to stop waiting photon::thread_interrupt(th, reason); @@ -1662,8 +1660,8 @@ TEST(interrupt, condition_variable) { TEST(interrupt, semaphore) { photon::semaphore sem(0); auto th = photon::CURRENT; - int reason = rand(); - while (reason == 0) reason = rand(); + int reason = photon::rand32(); + while (reason == 0) reason = photon::rand32(); photon::thread_create11([th, reason]() { // any errno except 0 is able to stop waiting photon::thread_interrupt(th, reason); @@ -1763,7 +1761,6 @@ TEST(future, test2) { int main(int argc, char** arg) { - srand(time(0)); if (!photon::is_using_default_engine()) return 0; ::testing::InitGoogleTest(&argc, arg); gflags::ParseCommandLineFlags(&argc, &arg, true); diff --git a/thread/thread.cpp b/thread/thread.cpp index 8f9a7240..f44e3492 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -919,7 +919,7 @@ R"( RunQ rq; if (unlikely(!rq.current)) LOG_ERROR_RETURN(ENOSYS, nullptr, "Photon not initialized in this vCPU (OS thread)"); - size_t randomizer = (rand() % 512) * 8; + size_t randomizer = (photon::rand32() % 512) * 8; // stack contains struct, randomizer space, and reserved_space size_t least_stack_size = sizeof(thread) + randomizer + 63 + reserved_space; // at least a whole page for mprotect