Skip to content

Update setprecision docstring and add NEWS entry for thread-safe behavior #58605

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Language changes
is considered a bug fix ([#47102])

- The `hash` algorithm and its values have changed. Most `hash` specializations will remain correct and require no action. Types that reimplement the core hashing logic independently, such as some third-party string packages do, may require a migration to the new algorithm. ([#57509])
- `setprecision` now utilizes `ScopedValue`, enhancing thread safety when setting precision levels. This change allows for safer precision adjustments in multi-threaded environments. ([#51362])

Compiler/Runtime improvements
-----------------------------
Expand Down
14 changes: 9 additions & 5 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,15 @@ Set the 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

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.
!!! note
Temporarily sets the precision for BigFloat operations to `precision` bits within the
scope of function `f`. This function is now thread-safe due to the use of `ScopedValue`,
ensuring that precision settings do not interfere across threads.

Example:
setprecision(256) do
# Operations here use 256-bit precision
end

!!! compat "Julia 1.8"
The `base` keyword requires at least Julia 1.8.
Expand Down