Skip to content

Commit 697e22c

Browse files
wooster0Vexu
authored andcommitted
fix: resolve data race in std.Progress.maybeRefresh()
It seems we can simply lock the update mutex a little earlier.
1 parent 0b7b4b7 commit 697e22c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/std/Progress.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) *N
172172
/// Updates the terminal if enough time has passed since last update. Thread-safe.
173173
pub fn maybeRefresh(self: *Progress) void {
174174
if (self.timer) |*timer| {
175-
const now = timer.read();
176-
if (now < self.initial_delay_ns) return;
177175
if (!self.update_mutex.tryLock()) return;
178176
defer self.update_mutex.unlock();
177+
const now = timer.read();
178+
if (now < self.initial_delay_ns) return;
179179
// TODO I have observed this to happen sometimes. I think we need to follow Rust's
180180
// lead and guarantee monotonically increasing times in the std lib itself.
181181
if (now < self.prev_refresh_timestamp) return;

0 commit comments

Comments
 (0)