Skip to content

Commit

Permalink
fix(task): call vTaskDelete at end of std::thread in `task::run_o…
Browse files Browse the repository at this point in the history
…n_core_non_blocking` (#353)

* 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
  • Loading branch information
finger563 authored Dec 19, 2024
1 parent 4431bd7 commit 32367dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion components/task/include/run_on_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion components/task/src/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,5 @@ void Task::thread_function() {
}
}
#endif // ESP_PLATFORM
}
} // while (started_)
}

0 comments on commit 32367dd

Please sign in to comment.