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

Fix intermittent threaded loop executed in order test warning #44479

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion test/threads_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ end

# parallel loop with parallel atomic addition
function threaded_loop(a, r, x)
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
counter = Threads.Atomic{Int}(Threads.nthreads())
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
@threads for i in r
# synchronize the start given that each partition is started sequentially,
# meaning that without the wait, if the loop is too fast the iteration can happen in order
if counter[] != 0
Threads.atomic_sub!(counter, 1)
while counter[] != 0
GC.safepoint()
ccall(:jl_cpu_pause, Cvoid, ())
end
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
end
j = i - firstindex(r) + 1
a[j] = 1 + atomic_add!(x, 1)
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
end
Expand All @@ -93,7 +103,7 @@ function test_threaded_loop_and_atomic_add()
# and were unique (via pigeon-hole principle).
@test !(false in found)
if was_inorder && nthreads() > 1
println(stderr, "Warning: threaded loop executed in order")
@warn "threaded loop executed in order" nthreads() r
end
end
end
Expand Down