From fd95eabc8d5ac6f88b97671801b836f7b6f110a9 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Thu, 7 Sep 2023 16:34:24 -0300 Subject: [PATCH 1/2] uv_unref needs iolock --- base/Base.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/base/Base.jl b/base/Base.jl index 4fb29672f35d7..a330cbfe1dd4b 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -600,7 +600,9 @@ function __init__() @static if !Sys.iswindows() # triggering a profile via signals is not implemented on windows cond = Base.AsyncCondition() + Base.iolock_begin() # uv_unref needs lock Base.uv_unref(cond.handle) + Base.iolock_end() PROFILE_PRINT_COND[] = cond ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), PROFILE_PRINT_COND[].handle) errormonitor(Threads.@spawn(profile_printing_listener())) From 1ff333a8545a0cc5dc971a063fd3e1139a8fc3a8 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 7 Sep 2023 17:43:24 -0400 Subject: [PATCH 2/2] Move lock into uv_ref and uv_unref --- base/Base.jl | 2 -- base/libuv.jl | 13 +++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/base/Base.jl b/base/Base.jl index a330cbfe1dd4b..4fb29672f35d7 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -600,9 +600,7 @@ function __init__() @static if !Sys.iswindows() # triggering a profile via signals is not implemented on windows cond = Base.AsyncCondition() - Base.iolock_begin() # uv_unref needs lock Base.uv_unref(cond.handle) - Base.iolock_end() PROFILE_PRINT_COND[] = cond ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), PROFILE_PRINT_COND[].handle) errormonitor(Threads.@spawn(profile_printing_listener())) diff --git a/base/libuv.jl b/base/libuv.jl index 24a04f5bcad78..4c56af29e7e60 100644 --- a/base/libuv.jl +++ b/base/libuv.jl @@ -103,8 +103,17 @@ uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(_UVError(prefix, c) eventloop() = ccall(:jl_global_event_loop, Ptr{Cvoid}, ()) -uv_unref(h::Ptr{Cvoid}) = ccall(:uv_unref, Cvoid, (Ptr{Cvoid},), h) -uv_ref(h::Ptr{Cvoid}) = ccall(:uv_ref, Cvoid, (Ptr{Cvoid},), h) +function uv_unref(h::Ptr{Cvoid}) + iolock_begin() + ccall(:uv_unref, Cvoid, (Ptr{Cvoid},), h) + iolock_end() +end + +function uv_ref(h::Ptr{Cvoid}) + iolock_begin() + ccall(:uv_ref, Cvoid, (Ptr{Cvoid},), h) + iolock_end() +end function process_events() return ccall(:jl_process_events, Int32, ())