Project

General

Profile

Bug #18873

Need to use thread safe random number generation (unless c++11 already provides this)

Added by David Zafman over 2 years ago. Updated about 2 years ago.

Status:
New
Priority:
Normal
Category:
common
Target version:
-
Start date:
02/09/2017
Due date:
% Done:

0%

Source:
Community (dev)
Tags:
rand, random
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:

Description

We are using rand() throughout the code which man says isn't thread safe. We should determine if rand() with c++11 is thread safe or not. If it isn't use some other variant like rand_r(), boost? or c++11 features.

History

#1 Updated by Jos Collin over 2 years ago

David Zafman wrote:

We are using rand() throughout the code which man says isn't thread safe. We should determine if rand() with c++11 is thread safe or not. If it isn't use some other variant like rand_r(), boost? or c++11 features.

The rand() function is not thread-safe. rand() range is often significantly smaller than you want it to be. The C++ <random> library gives you much more powerful PRNGs.

#2 Updated by Jos Collin over 2 years ago

  • Category set to common
  • Assignee set to Jos Collin
  • Source set to Community (dev)

#3 Updated by Jos Collin over 2 years ago

  • Tags set to rand, random

#4 Updated by Jos Collin about 2 years ago

  • Assignee changed from Jos Collin to Jesse Williamson

Jesse,

I didn't get time to focus on this. Assigning this to you, as you have a PR that implements random number generation.
https://github.com/ceph/ceph/pull/15341

Thanks,
Jos Collin

#5 Updated by Jesse Williamson about 2 years ago

Just to make sure the signal isn't lost in the noise, the facility in this PR is an interface to the C++11 standard random number facility that will be used to provide fixes for this bug report, once approved:
https://github.com/ceph/ceph/pull/15341

Also available in: Atom PDF