#Zig Threads in ziglearn.org

1 messages · Page 1 of 1 (latest)

earnest sigil
#

Hey, I was trying to learn zig threads in ziglearn.org
I tried the code that was provided:

const std = @import("std");

pub fn main() !void {}

fn ticker(step: u8) void {
    while (true) {
        std.time.sleep(1 * std.time.ns_per_s);
        tick += @as(isize, step);
    }
}

var tick: isize = 0;

test "threading" {
    var thread = try std.Thread.spawn(.{}, ticker, .{@as(u8, 1)});
    _ = thread;
    try expect(tick == 0);
    std.time.sleep(3 * std.time.ns_per_s / 2);
    try expect(tick == 1);
}

And I got the following result in the terminal:

main.zig:17:9: error: use of undeclared identifier 'expect'
    try expect(tick == 0);

Can anyone help me understand why its happening?

lilac spade
#

expect is not defined (in that snippet)

#

it's in std.testing

#

either add a top-level const expect = std.testing.expect; or replace usage of expect by the fully qualified name

earnest sigil
#

Thank you it worked!