mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
Use thread local random number generator (#20708)
This commit is contained in:
parent
116bda8f05
commit
15a51b7c65
1 changed files with 1 additions and 6 deletions
|
@ -202,12 +202,7 @@ template <typename T>
|
||||||
void FillRandom(T *data) {
|
void FillRandom(T *data) {
|
||||||
RAY_CHECK(data != nullptr);
|
RAY_CHECK(data != nullptr);
|
||||||
|
|
||||||
// NOTE(pcm): The right way to do this is to have one absl::BitGen per
|
thread_local absl::BitGen generator;
|
||||||
// thread (using the thread_local keyword), but that's not supported on
|
|
||||||
// older versions of macOS (see https://stackoverflow.com/a/29929949)
|
|
||||||
static std::mutex random_engine_mutex;
|
|
||||||
std::lock_guard<std::mutex> lock(random_engine_mutex);
|
|
||||||
static absl::BitGen generator;
|
|
||||||
for (size_t i = 0; i < data->size(); i++) {
|
for (size_t i = 0; i < data->size(); i++) {
|
||||||
(*data)[i] = static_cast<uint8_t>(
|
(*data)[i] = static_cast<uint8_t>(
|
||||||
absl::Uniform(generator, 0, std::numeric_limits<uint8_t>::max()));
|
absl::Uniform(generator, 0, std::numeric_limits<uint8_t>::max()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue