Skip to content

Commit

Permalink
coro: remove io_ack from scheduler
Browse files Browse the repository at this point in the history
The logic here is not sound and actually is the root cause for #31
The yield enough should be enough for valid io submission, in theory if
the task is cancelled immediately something weird could happen.. It is
better to implement #44 to make sure no such bug exists and are catch
early.

Fixes #31
  • Loading branch information
Cloudef committed Jan 4, 2025
1 parent 1d49014 commit 420a0cc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bugs/31.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ pub fn spawner(tmp: []usize) !void {
for (0..500) |i| {
_ = try scheduler.spawn(protection, .{ logger, .{ i, tmp } }, .{});
}
try delay(std.time.ns_per_s * 25); // logging takes 20s + 5s for safety
try delay(std.time.ns_per_s * 25); // logging takes ~25s
for (tmp, 0..) |value, index| {
logInfo("{}. {}\n", .{ index + 1, value });
if (value != 100) @panic("something went bonkers (2)");
}
//just test for protection layer
return error.Unexpected;
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn build(b: *std.Build) void {
const bug_step = b.step("bug", "Run regression tests");
inline for (.{
.@"22",
// .@"31", TODO: fix this
.@"31",
}) |bug| {
const exe = b.addExecutable(.{
.name = @tagName(bug),
Expand Down
2 changes: 0 additions & 2 deletions src/coro/Scheduler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const options = @import("../coro.zig").options;

allocator: std.mem.Allocator,
io: aio.Dynamic,
io_ack: u8 = 0,
running: Frame.List = .{},
completed: Frame.List = .{},
state: enum { init, tear_down } = .init,
Expand Down Expand Up @@ -83,7 +82,6 @@ pub fn spawn(self: *@This(), comptime func: anytype, args: anytype, opts: SpawnO
/// Returns the number of tasks running.
pub fn tick(self: *@This(), mode: aio.Dynamic.CompletionMode) aio.Error!usize {
if (self.state == .tear_down) return error.Unexpected;
self.io_ack +%= 1;
if (self.completed.first) |first| {
var next: ?*Frame.List.Node = first;
while (next) |node| {
Expand Down
5 changes: 1 addition & 4 deletions src/coro/io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pub fn do(operations: anytype, status: Frame.Status) Error!u16 {
}

// wait until scheduler actually submits our work
const ack = frame.scheduler.io_ack;
while (ack == frame.scheduler.io_ack) {
Frame.yield(status);
}
Frame.yield(status);

// check if this was a cancel
if (whole.num_operations > 0) {
Expand Down

0 comments on commit 420a0cc

Please sign in to comment.