MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ terminate_all_tasks()

void MayaFlux::Vruta::TaskScheduler::terminate_all_tasks ( )

Terminate and clear all tasks.

Definition at line 341 of file Scheduler.cpp.

342{
343 for (auto& entry : m_tasks) {
344 if (entry.routine && entry.routine->is_active()) {
345 entry.routine->set_should_terminate(true);
346 }
347 }
348
349 for (auto& entry : m_tasks) {
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;
360 for (auto& entry : m_tasks) {
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
390 m_tasks.clear();
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.

References MayaFlux::Journal::CoroutineScheduling, m_tasks, MF_PRINT, MF_WARN, and MayaFlux::Journal::Vruta.