zig

fork of https://codeberg.org/ziglang/zig
Log | Tree | Refs | README | LICENSE

commit 28ef79ea808fdb8e00b6d88d1565314a9e412768 (tree)
parent 3ed9ef3e6bed3fef6d6cad07920d08b28e20ec3e
Author: Jay Petacat <jay@jayschwa.net>
Date:   Wed,  4 May 2022 10:43:27 -0400

std: Single-threaded `panicImpl` sleep is unreachable (#11569)

Adding `unreachable` prevents the futex code from being inspected during
a single-threaded build. Without futex, first draft BYOS packages don't
need to implement `nanosleep` to get a single-threaded "hello world"
program working.

Use of `assert()` did not achieve the desired effect of avoiding futex
in a single-threaded build.
Diffstat:
Mlib/std/debug.zig | 1+
1 file changed, 1 insertion(+), 0 deletions(-)

diff --git a/lib/std/debug.zig b/lib/std/debug.zig @@ -340,6 +340,7 @@ pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize if (panicking.fetchSub(1, .SeqCst) != 1) { // Another thread is panicking, wait for the last one to finish // and call abort() + if (builtin.single_threaded) unreachable; // Sleep forever without hammering the CPU var futex = std.atomic.Atomic(u32).init(0);