Skip to content
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

Thread safety #23

Open
dsfenn opened this issue Aug 15, 2020 · 1 comment
Open

Thread safety #23

dsfenn opened this issue Aug 15, 2020 · 1 comment

Comments

@dsfenn
Copy link

dsfenn commented Aug 15, 2020

The various calls to grisu() are not thread-safe, due to the use of the module-level DIGITS buffer:

function grisu(v::AbstractFloat, mode, requested_digits)
    return tuple(Base.Grisu.grisu(v, mode, requested_digits)..., Base.Grisu.DIGITS)
end

Different threads may write to this buffer before it is read by the calling function, causing corrupted output. In my particular case, this was corrupting the axis labels on plots generated in a parallel for loop.

This can be fixed by defining the function as:

function grisu(v::AbstractFloat, mode, requested_digits)
    return tuple(Base.Grisu.grisu(v, mode, requested_digits)..., Base.Grisu.DIGITSs[Threads.threadid()])
end
@isentropic
Copy link
Collaborator

Do you have any idea if in the current implementation with Ryu the thread safety is an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants