From 1824bee579fffad3f17b639ebb1a94fd890ad68d Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 8 Jul 2024 17:58:41 -0400 Subject: [PATCH] Progress: suppress tsan races This removes the undefined behavior, but not the actual races. Closes #20477 --- lib/std/Progress.zig | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 2028e95dd550..dcbb12e69bc2 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -285,13 +285,11 @@ pub const Node = struct { assert(parent == .none or @intFromEnum(parent) < node_storage_buffer_len); const storage = storageByIndex(free_index); - storage.* = .{ - .completed_count = 0, - .estimated_total_count = std.math.lossyCast(u32, estimated_total_items), - .name = [1]u8{0} ** max_name_len, - }; + @atomicStore(u32, &storage.completed_count, 0, .monotonic); + @atomicStore(u32, &storage.estimated_total_count, std.math.lossyCast(u32, estimated_total_items), .monotonic); const name_len = @min(max_name_len, name.len); - @memcpy(storage.name[0..name_len], name[0..name_len]); + for (storage.name[0..name_len], name[0..name_len]) |*dest, src| @atomicStore(u8, dest, src, .monotonic); + for (storage.name[name_len..]) |*dest| @atomicStore(u8, dest, 0, .monotonic); const parent_ptr = parentByIndex(free_index); assert(parent_ptr.* == .unused); @@ -765,7 +763,7 @@ fn serialize(serialized_buffer: *Serialized.Buffer) Serialized { var begin_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire); while (begin_parent != .unused) { const dest_storage = &serialized_buffer.storage[serialized_len]; - @memcpy(&dest_storage.name, &storage_ptr.name); + for (&dest_storage.name, &storage_ptr.name) |*dest, *src| dest.* = @atomicLoad(u8, src, .monotonic); dest_storage.estimated_total_count = @atomicLoad(u32, &storage_ptr.estimated_total_count, .acquire); dest_storage.completed_count = @atomicLoad(u32, &storage_ptr.completed_count, .monotonic); const end_parent = @atomicLoad(Node.Parent, parent_ptr, .acquire);