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_) }