Skip to content

Commit

Permalink
rework the thread unsafe test to make it more meaningful
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed Nov 3, 2021
1 parent 5fffa44 commit 87ea73f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions stdlib/LinearAlgebra/test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -651,16 +651,16 @@ end

@testset "thread unsafe" begin
prev_num_threads = BLAS.get_num_threads()
# thread unsafe
@async BLAS.with_num_threads(1) do
context_num_threads = 1
# task A
t = @async BLAS.with_num_threads(context_num_threads) do
sleep(0.5)
end
sleep(0.1)

context_num_threads = BLAS.get_num_threads()
@test context_num_threads == 1

sleep(0.5) # wait for the task to finish
# check that main thread is affected by task A
@test BLAS.get_num_threads() == context_num_threads
# when the task finishes, the num threads get restored
wait(t)
@test prev_num_threads == BLAS.get_num_threads()
end
end
Expand Down

0 comments on commit 87ea73f

Please sign in to comment.