-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentationmultithreadingBase.Threads and related functionalityBase.Threads and related functionality
Description
I'm seeing some cases (in 1.3-rc4) where Threads.@threads is missing some of the iteration assignments. With this example, 1 or a few are missed most of the times I run this.
Wrapping vals[i] = false in a spinlock fixes this, but I was under the impression that a @threads approach like this, where each element in the vals array is accessed once, shouldn't need a spinlock to avoid race conditions.
n = 10
vals = trues(n)
threadsUsed = Int[]
Threads.@threads for i = 1:n
vals[i] = false
!in(Threads.threadid(), threadsUsed) && push!(threadsUsed, Threads.threadid())
sleep(0.1)
end
if any(vals) #Check that all elements have been iterated (set to false)
@show vals
@show threadsUsed
@show Threads.nthreads()
endvals = Bool[0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
threadsUsed = [1, 2, 3, 5, 4]
Threads.nthreads() = 5
Metadata
Metadata
Assignees
Labels
docsThis change adds or pertains to documentationThis change adds or pertains to documentationmultithreadingBase.Threads and related functionalityBase.Threads and related functionality