From 77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 10 Jun 2018 01:13:51 -0400 Subject: breaking syntax change: orelse keyword instead of ?? (#1096) use the `zig-fmt-optional-default` branch to have zig fmt automatically do the changes. closes #1023 --- std/atomic/queue.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'std/atomic/queue.zig') diff --git a/std/atomic/queue.zig b/std/atomic/queue.zig index 142c958173..4f856d9e01 100644 --- a/std/atomic/queue.zig +++ b/std/atomic/queue.zig @@ -33,8 +33,8 @@ pub fn Queue(comptime T: type) type { pub fn get(self: *Self) ?*Node { var head = @atomicLoad(*Node, &self.head, AtomicOrder.SeqCst); while (true) { - const node = head.next ?? return null; - head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return node; + const node = head.next orelse return null; + head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse return node; } } }; -- cgit v1.2.3 From fdd9cf09287b5e397ad9b2c960c833a7de075e4c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 12 Jun 2018 15:14:32 -0400 Subject: better debugging for CI failures of std.atomic --- std/atomic/queue.zig | 14 ++++++++++++-- std/atomic/stack.zig | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'std/atomic/queue.zig') diff --git a/std/atomic/queue.zig b/std/atomic/queue.zig index 4f856d9e01..2a48407383 100644 --- a/std/atomic/queue.zig +++ b/std/atomic/queue.zig @@ -94,8 +94,18 @@ test "std.atomic.queue" { for (getters) |t| t.wait(); - std.debug.assert(context.put_sum == context.get_sum); - std.debug.assert(context.get_count == puts_per_thread * put_thread_count); + if (context.put_sum != context.get_sum) { + std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum); + } + + if (context.get_count != puts_per_thread * put_thread_count) { + std.debug.panic( + "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", + context.get_count, + u32(puts_per_thread), + u32(put_thread_count), + ); + } } fn startPuts(ctx: *Context) u8 { diff --git a/std/atomic/stack.zig b/std/atomic/stack.zig index 77fa1a9100..c6b368b990 100644 --- a/std/atomic/stack.zig +++ b/std/atomic/stack.zig @@ -97,8 +97,18 @@ test "std.atomic.stack" { for (getters) |t| t.wait(); - std.debug.assert(context.put_sum == context.get_sum); - std.debug.assert(context.get_count == puts_per_thread * put_thread_count); + if (context.put_sum != context.get_sum) { + std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum); + } + + if (context.get_count != puts_per_thread * put_thread_count) { + std.debug.panic( + "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", + context.get_count, + u32(puts_per_thread), + u32(put_thread_count), + ); + } } fn startPuts(ctx: *Context) u8 { -- cgit v1.2.3 From fc87f6e417d206a88b581b77d3a5494ae4c978dd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 13 Jun 2018 11:57:57 -0400 Subject: fix race condition bug in test harness of std.atomic --- std/atomic/queue.zig | 7 +++---- std/atomic/stack.zig | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'std/atomic/queue.zig') diff --git a/std/atomic/queue.zig b/std/atomic/queue.zig index 2a48407383..3dc64dbea2 100644 --- a/std/atomic/queue.zig +++ b/std/atomic/queue.zig @@ -124,15 +124,14 @@ fn startPuts(ctx: *Context) u8 { fn startGets(ctx: *Context) u8 { while (true) { + const last = @atomicLoad(u8, &ctx.puts_done, builtin.AtomicOrder.SeqCst) == 1; + while (ctx.queue.get()) |node| { std.os.time.sleep(0, 1); // let the os scheduler be our fuzz _ = @atomicRmw(isize, &ctx.get_sum, builtin.AtomicRmwOp.Add, node.data, builtin.AtomicOrder.SeqCst); _ = @atomicRmw(usize, &ctx.get_count, builtin.AtomicRmwOp.Add, 1, builtin.AtomicOrder.SeqCst); } - if (@atomicLoad(u8, &ctx.puts_done, builtin.AtomicOrder.SeqCst) == 1) { - break; - } + if (last) return 0; } - return 0; } diff --git a/std/atomic/stack.zig b/std/atomic/stack.zig index c6b368b990..9e81d89257 100644 --- a/std/atomic/stack.zig +++ b/std/atomic/stack.zig @@ -127,15 +127,14 @@ fn startPuts(ctx: *Context) u8 { fn startGets(ctx: *Context) u8 { while (true) { + const last = @atomicLoad(u8, &ctx.puts_done, builtin.AtomicOrder.SeqCst) == 1; + while (ctx.stack.pop()) |node| { std.os.time.sleep(0, 1); // let the os scheduler be our fuzz _ = @atomicRmw(isize, &ctx.get_sum, builtin.AtomicRmwOp.Add, node.data, builtin.AtomicOrder.SeqCst); _ = @atomicRmw(usize, &ctx.get_count, builtin.AtomicRmwOp.Add, 1, builtin.AtomicOrder.SeqCst); } - if (@atomicLoad(u8, &ctx.puts_done, builtin.AtomicOrder.SeqCst) == 1) { - break; - } + if (last) return 0; } - return 0; } -- cgit v1.2.3