From f44a58e5e6528d1bd370143460db06f263b06f45 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Mon, 27 May 2024 13:55:47 +0200 Subject: [PATCH] Use a pidfile to guard againstn runtime corruption. --- Project.toml | 6 ++++-- src/rtlib.jl | 17 ++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index bbca5d6a..2c3ba4e8 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.26.4" [deps] ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04" +FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LLVM = "929cbde3-209d-540e-8aea-75f648917ca0" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" @@ -15,11 +16,12 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] ExprTools = "0.1" +FileWatching = "1" InteractiveUtils = "1" +LLVM = "7.1" Libdl = "1" Logging = "1" -UUIDs = "1" -LLVM = "7.1" Scratch = "1" TimerOutputs = "0.5" +UUIDs = "1" julia = "1.8" diff --git a/src/rtlib.jl b/src/rtlib.jl index 289cad76..130adc5e 100644 --- a/src/rtlib.jl +++ b/src/rtlib.jl @@ -15,6 +15,8 @@ end # GPU run-time library # +using FileWatching.Pidfile: mkpidlock + ## higher-level functionality to work with runtime functions @@ -115,10 +117,8 @@ function build_runtime(@nospecialize(job::CompilerJob)) mod end -const runtime_lock = ReentrantLock() - @locked function load_runtime(@nospecialize(job::CompilerJob)) - lock(runtime_lock) do + mkpidlock("$(compile_cache).lock"; stale_age=5) do slug = runtime_slug(job) if !supports_typed_pointers(context()) slug *= "-opaque" @@ -139,14 +139,8 @@ const runtime_lock = ReentrantLock() if lib === nothing @debug "Building the GPU runtime library at $path" - mkpath(compile_cache) lib = build_runtime(job) - - # atomic write to disk - temp_path, io = mktemp(dirname(path); cleanup=false) - write(io, lib) - close(io) - Base.rename(temp_path, path; force=true) + write(path, lib) end return lib @@ -156,8 +150,9 @@ end # remove the existing cache # NOTE: call this function from global scope, so any change triggers recompilation. function reset_runtime() - lock(runtime_lock) do + mkpidlock("$(compile_cache).lock"; stale_age=5) do rm(compile_cache; recursive=true, force=true) + mkpath(compile_cache) end return