From fad223d92ed34caac163695cc2a32cba80267c32 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 12 Jun 2024 17:16:42 -0700 Subject: [PATCH] std.Progress: use a recursive mutex for stderr --- lib/std/Progress.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index c7dffe4c3f..ef9099be99 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -521,6 +521,8 @@ fn windowsApiUpdateThreadRun() void { /// Allows the caller to freely write to stderr until `unlockStdErr` is called. /// /// During the lock, any `std.Progress` information is cleared from the terminal. +/// +/// The lock is recursive; the same thread may hold the lock multiple times. pub fn lockStdErr() void { stderr_mutex.lock(); clearWrittenWithEscapeCodes() catch {}; @@ -1378,4 +1380,7 @@ const have_sigwinch = switch (builtin.os.tag) { else => false, }; -var stderr_mutex: std.Thread.Mutex = .{}; +/// The primary motivation for recursive mutex here is so that a panic while +/// stderr mutex is held still dumps the stack trace and other debug +/// information. +var stderr_mutex = std.Thread.Mutex.Recursive.init;