std::future<void> do_while(Body body) { auto p = std::make_shared<std::promise<void>>(); std::async(std::launch::async, [=]() { try { task_loop(p, body); } catch (...) { } }); return p->get_future(); }
void task_loop(std::shared_ptr<std::promise<void>> p, Body body) { auto s = body().share(); then(s, [=](auto f) { try { if (f.get()) task_loop(p, body); else p->set_value(); } catch (...) { } }); }
int main() { Setup(); Post(); DEBUG(" *** STARTING TASKS ***\n"); task_init(); while (1) { //run main task task_loop(); //run system tasks task_system_loop(); //sleep now task_sleep(); } }
void lock(struct lock* m) { #if SYNC task_loop(trylock(m) == -1); #endif }