Pattern how to use and trigger a background daemon fiber.
static bool shutdown_flag = false;
{
return;
while(!shutdown_flag) {
t += interval;
}
}
static zth::Signal triggerSomeDaemon(
"someDaemon trigger");
void someDaemon()
{
async trigger(&triggerSomeDaemon, 1);
while(!shutdown_flag) {
printf("daemon wakeup\n");
triggerSomeDaemon.wait();
}
}
void foo()
{
printf("foo\n");
triggerSomeDaemon.signal();
}
{
gate.wait();
shutdown_flag = true;
return 0;
}
Fiber-aware barrier/gate.
void signal(bool queue=true, bool queueEveryTime=false) noexcept
Convenient wrapper around struct timespec that contains a time interval.
constexpr bool isNegative() const noexcept
Convenient wrapper around struct timespec that contains an absolute timestamp.
Makes the fiber pass the given gate upon exit.
int main_fiber(int argc, char **argv)
void nap(Timestamp const &sleepUntil)
Sleep until the given time stamp.
#define zth_fiber(...)
Prepare every given function to become a fiber by async.
#define async
Run a function as a new fiber.