I was trying to hunt down an obnoxious infinite loop and I needed to slow down the calls. Of course, I bumped into the fact that sleep has been removed from effectively everywhere.
I had to do:
const linux = std.os.linux;
var req = linux.timespec{ .sec = 1, .nsec = 0 };
_ = linux.nanosleep(&req, null);
just so I could run down my error.
Is there an alternative? Or could we at least get something like std.debug.sleep like we have std.debug.print?
Not sure if it’s particularly “idiomatic”, but you could always create a standalone sleep function with an adhoc single-threaded Io object (which should be fairly cheap to create):
Out of curiosity, if it’s an infinite loop, what’s the reason you’re debugging with sleeps over something like a conditional breakpoint? Introducing variable(s) to trigger on if need be.
To add onto what @floooh and @asibahi said, there is already a global instance available std.Io.Threaded.global_single_threaded
I don’t recommend using it directly, instead use std.Options.debug_io, which is the same by default but can be overridden.
There is also std.Options.debug_threaded_io, which is again the same, but can be overridden separately for some reason.
I think the only reason this exists is so std.start can set arg0 without forcing the compilation of std.Io.Threaded.global_single_threaded by letting you override it (can be disabled with null).