From 662fe7629454fdf621ffc795ac284824f9310e10 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Thu, 19 Dec 2024 09:41:27 -0600 Subject: [PATCH] fix(task): call `vTaskDelete` at end of `std::thread` in `task::run_on_core_non_blocking` * Ensure the detached task function calls `vTaskDelete(nullptr)` instead of returning. It is not needed in the `Task` itself because we do a `join` on that thread instead of detaching --- components/task/include/run_on_core.hpp | 8 +++++++- components/task/src/task.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/task/include/run_on_core.hpp b/components/task/include/run_on_core.hpp index ce8b15d1d..711cdd25c 100644 --- a/components/task/include/run_on_core.hpp +++ b/components/task/include/run_on_core.hpp @@ -151,7 +151,13 @@ static void run_on_core_non_blocking(const auto &f, int core_id, size_t stack_si f(); return; } - auto thread = std::thread(f); + auto thread = std::thread( + [](const auto &f) { + f(); + // delete ourselves (the task that was created by the thread) + vTaskDelete(nullptr); + }, + f); thread.detach(); } diff --git a/components/task/src/task.cpp b/components/task/src/task.cpp index 10aac7f90..944b8ed21 100644 --- a/components/task/src/task.cpp +++ b/components/task/src/task.cpp @@ -268,5 +268,5 @@ void Task::thread_function() { } } #endif // ESP_PLATFORM - } + } // while (started_) }