MayaFlux 0.3.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 337 of file Scheduler.cpp.

338{
339 for (auto& entry : m_tasks) {
340 if (entry.routine && entry.routine->is_active()) {
341 entry.routine->set_should_terminate(true);
342 }
343 }
344
345 for (auto& entry : m_tasks) {
346 if (entry.routine && entry.routine->is_active()) {
347 entry.routine->force_resume();
348 }
349 }
350
351 constexpr int MAX_ATTEMPTS = 3;
352 for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
353 std::this_thread::sleep_for(std::chrono::milliseconds(5));
354
355 bool any_active = false;
356 for (auto& entry : m_tasks) {
357 if (entry.routine && entry.routine->is_active()) {
358 any_active = true;
359 entry.routine->force_resume();
360 }
361 }
362
363 if (!any_active) {
364 break;
365 }
366 }
367
368 bool all_done = true;
369 for (const auto& entry : m_tasks) {
370 if (entry.routine && entry.routine->is_active()) {
371 all_done = false;
373 "Coroutine '{}' stuck after {} attempts - forcing destruction",
374 entry.name, MAX_ATTEMPTS);
375 }
376 }
377
378 if (!all_done) {
380 "Some coroutines did not complete - forcing destruction");
381 } else {
383 "All coroutines terminated successfully");
384 }
385
386 m_tasks.clear();
387}
#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.