mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
fix: resolve data race in std.Progress.maybeRefresh()
It seems we can simply lock the update mutex a little earlier.
This commit is contained in:
parent
0b7b4b7e97
commit
697e22caa4
@ -172,10 +172,10 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) *N
|
||||
/// Updates the terminal if enough time has passed since last update. Thread-safe.
|
||||
pub fn maybeRefresh(self: *Progress) void {
|
||||
if (self.timer) |*timer| {
|
||||
const now = timer.read();
|
||||
if (now < self.initial_delay_ns) return;
|
||||
if (!self.update_mutex.tryLock()) return;
|
||||
defer self.update_mutex.unlock();
|
||||
const now = timer.read();
|
||||
if (now < self.initial_delay_ns) return;
|
||||
// TODO I have observed this to happen sometimes. I think we need to follow Rust's
|
||||
// lead and guarantee monotonically increasing times in the std lib itself.
|
||||
if (now < self.prev_refresh_timestamp) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user