Skip to content

Commit

Permalink
test multithreaded logging
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Feb 17, 2025
1 parent e331deb commit 1c24eeb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stdlib/Logging/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,14 @@ end
@test isempty(undoc)
end

@testset "thread safety" begin
cmd = `$(Base.julia_cmd()) -t4 $(joinpath(@__DIR__, "threads_exec.jl"))`
fname = tempname()
f = open(fname, "w")
redirect_stderr(f) do
success(run(cmd))
end
close(f)
end

end
13 changes: 13 additions & 0 deletions stdlib/Logging/test/threads_exec.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Logging

function test_threads_exec(n)
Threads.@threads for i in 1:n
x = rand()
@debug "iteration" i x Threads.threadid()
@info "iteration" i x Threads.threadid()
@warn "iteration" i x Threads.threadid()
@error "iteration" i x Threads.threadid()
end
end

test_threads_exec(100000)

0 comments on commit 1c24eeb

Please sign in to comment.