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

add locks in test_threads #292

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
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
15 changes: 10 additions & 5 deletions test/test_threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
prog = ProgressMeter.ProgressUnknown(desc="Attempts at exceeding trigger:")
vals = Float64[]
threadsUsed = Int[]
lk = ReentrantLock()
Threads.@threads for _ in 1:1000
!in(Threads.threadid(), threadsUsed) && push!(threadsUsed, Threads.threadid())
push!(vals, rand())
valssum = sum(vals)
if sum(vals) <= trigger
valssum = lock(lk) do
push!(vals, rand())
return sum(vals)
end
if valssum <= trigger
ProgressMeter.next!(prog)
elseif !prog.done
ProgressMeter.finish!(prog)
Expand All @@ -47,8 +50,10 @@
threadsUsed = Int[]
Threads.@threads for _ in 1:100000
!in(Threads.threadid(), threadsUsed) && push!(threadsUsed, Threads.threadid())
push!(vals, -rand())
valssum = sum(vals)
valssum = lock(lk) do
push!(vals, -rand())
return sum(vals)
end
if valssum > thresh
ProgressMeter.update!(prog, valssum)
else
Expand Down
Loading