Skip to content

Non-thread safe use of setrounding #612

@Joel-Dahne

Description

@Joel-Dahne

The slow versions of the _round methods in src/interval/rounding.jl use BigFloat together with setrounding in a way that is not thread-safe. For setprecision there is a precision_lock defined at the top of the file that is used to make it thread-safe, but not such look is used for the setrounding. Starting Julia with two threads I could reliably produce errors with the following code

x = interval(BigFloat, 1)
y = sin(x)
Threads.@threads for _ in 1:1000
    z = sin(x)
    @assert isequal_interval(y, z)
end

In many cases (though not all) I also found that after running this loop even the non-threaded behavior is wrong. Most of the time this fails:

setrounding(BigFloat, RoundNearest) # Reset rounding in case this would be an issue
z = sin(x)
@assert isequal_interval(y, z)

So there is some global state that gets messed up.

I made a quick attempt at fixing this by adding locks around setround, but I could still not get it to work properly. So there might be something else that I'm missing as well.

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