-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors in the creation of std::random_device #249
Comments
A similar problem can occur on Arm64-based systems when spinlock_ttas lock() accesses std::uniform_int_distribution and the resulting call to std::random_device::_M_getval() causes a run-time error. |
The error happens at runtime - how should boost.fiber handle exhaustion of entropy? |
The problem we're facing is not about entropy, but caused by the fact that std::uniform_int_distribution's call to std::random_device in spinlock_ttas's lock() routine can fail with an exception although it is declared "noexcept", hence causing the program to abort. Our workaround looks similar to the code below:
|
Hi all,
I noticed some of our tests crashing inside Boost.Fiber. More specific, the constructor of
std::random_device
throws anstd::runtime_error
with the descriptionrandom_device: rdseed failed
which is not handled.Inside of Boost.Fiber,
std::random_device
s are constructed to seed static, thread local random number generators in the spinlock implementations as well as in the work stealing scheduler.fiber/include/boost/fiber/detail/spinlock_ttas.hpp
Line 42 in df4a190
fiber/src/algo/work_stealing.cpp
Line 68 in df4a190
At these locations, it is assumed that the construction is successful. However, the constructor might throw an implementation-defined exception if something goes wrong.
In our case, such failures occurred using the
libstdc++
released with GCC 10.1.0 on machines which support therdseed
instruction. In a situation where multiple threads are spawned and need to initialized these random number generators, the available entropy exhausted andrdseed
fails often enough forstd::random_device
to give up.This behavior was already reported in the GCC bugtracker and a fallback to
rdrand
had been added for the next (?) GCC release. This change does not guarantee, thatstd::random_device
is constructed successfully, but it makes it more likely. So it would be great if Boost.Fiber would handle possible errors.In the meantime, is there a good way for a user of Boost.Fiber to handle this error?
The text was updated successfully, but these errors were encountered: