IntervalRootFinding -- Multithreading causes random errors?

I have found some erratic behaviour for the IntervalRootFinding.jl package when using multithreading. Specifically, when using multiple threads, the roots interface will sometimes return either false positives for non-existing roots, or fail to identify roots. Moreover, the errors vary at every run.

The minimum working example below repeatedly looks for roots on an interval without roots, and then counts the number of unique roots found. It should always return 1. When using one thread, everything is fine, but as soon as I run the same code with multiple threads, random errors start creeping up.

using IntervalRootFinding
let
	results = []
	Threads.@threads for iter in 1:1000	
		f(x) = (x^-1)-1
		result = roots(f, 0.0001..10000)
		push!(results, result)
	end
	length(unique(results))
end

Am I doing something wrong, or is this an issue within the package? I’ve tried this on multiple computers, and the problem already emerges when starting the REPL with multiple cores.

Maybe IntervalRootFinding.jl is not threads safe?
I skimmed the documentation and nothing struck me.

You may need to implement a parallelization strategy
using the API.

A PR for that or a documentation clarification would likely
be welcome.

I do not know about the details of your issue, but I saw that you push inside a threaded loop. I thought that pushing was not thread safe ? Could you try again with preassigned indices on the result array instead of pushing ?

The problem persists

using IntervalRootFinding
let
	results = Array{Any}(undef,1000)
	Threads.@threads for iter in 1:1000	
		f(x) = (x^-1)-1
		result = roots(f, 0.0001..10000)
		results[iter] = result
	end
	length(unique(results))
end

I am indeed afraid that IntervalRootFinding.jl is not threads safe, but I can neither figure out why, nor how to apply parallelisation in a safe alternative way.