-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
nosuspend await not safety-checked? #8666
Copy link
Copy link
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
This may be my own misunderstanding of how Zig's coroutines/async frames work, but the behavior of this snippet seems to contradict what nosuspend should do (at least in debug builds).
const std = @import("std");
pub fn main() !void {
nosuspend asyncMain();
}
fn asyncMain() void {
var f = async thing();
// resume f;
var x = nosuspend await f;
std.log.info("x: {}", .{x});
}
fn thing() u32 {
std.log.info("A, suspending", .{});
suspend;
std.log.info("B, returning", .{});
return 16;
}$ zig run example.zig
info: A, suspending
info: x: 0
By my understanding is that the await to f should suspend since the frame hasn't returned yet, but nosuspend should catch this?
And upon further inspection, the same happens if var x = nosuspend await f is replaced by
// ...
var x: u32 = 1;
nosuspend {
x = await f;
}
// ...Specifically, x is zeroed out
$ zig version
0.8.0-dev.1479+aa1c78056
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior