diff --git a/HISTORY.md b/HISTORY.md index ce4e9982a2c6b..c2f28cd68e2e2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -92,6 +92,8 @@ Multi-threading changes the first time it is called, and then always return the same result value of type `T` every subsequent time afterwards. There are also `OncePerThread{T}` and `OncePerTask{T}` types for similar usage with threads or tasks ([#55793]). +* `setprecision` utilizes `ScopedValue` for enhancing thread safety when setting precision levels. + This change allows for safer precision adjustments in multi-threaded environments. ([#51362]) Build system changes -------------------- diff --git a/base/mpfr.jl b/base/mpfr.jl index 25b7f0abe4b98..cd87dc2461e6e 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -1050,15 +1050,22 @@ _precision_with_base_2(::Type{BigFloat}) = """ setprecision([T=BigFloat,] precision::Int; base=2) -Set the precision (in bits, by default) to be used for `T` arithmetic. +Set the global precision (in bits, by default) to be used for `T` arithmetic. If `base` is specified, then the precision is the minimum required to give at least `precision` digits in the given `base`. -!!! warning +Example: +```julia + setprecision(256) +``` + +!!! note + Temporarily sets the precision for BigFloat operations to `precision` bits within the + scope of function `f`. This method is thread-safe due to the use of ScopedValue, ensuring + that precision settings do not interfere across threads. - This function is not thread-safe. It will affect code running on all threads, but - its behavior is undefined if called concurrently with computations that use the - setting. +!!! compat "Julia 1.12" + Thread safety via ScopedValue is guaranteed starting with Julia 1.12. !!! compat "Julia 1.8" The `base` keyword requires at least Julia 1.8.