Terminate and clear all tasks.
342{
344 if (entry.routine && entry.routine->is_active()) {
345 entry.routine->set_should_terminate(true);
346 }
347 }
348
350 if (entry.routine && entry.routine->is_active()) {
351 entry.routine->force_resume();
352 }
353 }
354
355 constexpr int MAX_ATTEMPTS = 3;
356 for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
357 std::this_thread::sleep_for(std::chrono::milliseconds(5));
358
359 bool any_active = false;
361 if (entry.routine && entry.routine->is_active()) {
362 any_active = true;
363 entry.routine->force_resume();
364 }
365 }
366
367 if (!any_active) {
368 break;
369 }
370 }
371
372 bool all_done = true;
373 for (
const auto& entry :
m_tasks) {
374 if (entry.routine && entry.routine->is_active()) {
375 all_done = false;
377 "Coroutine '{}' stuck after {} attempts - forcing destruction",
378 entry.name, MAX_ATTEMPTS);
379 }
380 }
381
382 if (!all_done) {
384 "Some coroutines did not complete - forcing destruction");
385 } else {
387 "All coroutines terminated successfully");
388 }
389
391}
#define MF_PRINT(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::vector< TaskEntry > m_tasks
@ CoroutineScheduling
Coroutine scheduling and temporal coordination (Vruta::TaskScheduler)
@ Vruta
Coroutines, schedulers, clocks, task management.