Skip to content

Thread safety #23

Description

@dsfenn

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions