mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
bugfix/pthread : pthread_detach implementation fixed to correctly delete pthread object when invoked after task completion
This commit is contained in:
@@ -395,8 +395,19 @@ int pthread_detach(pthread_t thread)
|
|||||||
TaskHandle_t handle = pthread_find_handle(thread);
|
TaskHandle_t handle = pthread_find_handle(thread);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
ret = ESRCH;
|
ret = ESRCH;
|
||||||
} else {
|
} else if (pthread->detached) {
|
||||||
|
// already detached
|
||||||
|
ret = EINVAL;
|
||||||
|
} else if (pthread->join_task) {
|
||||||
|
// already have waiting task to join
|
||||||
|
ret = EINVAL;
|
||||||
|
} else if (pthread->state == PTHREAD_TASK_STATE_RUN) {
|
||||||
|
// pthread still running
|
||||||
pthread->detached = true;
|
pthread->detached = true;
|
||||||
|
} else {
|
||||||
|
// pthread already stopped
|
||||||
|
pthread_delete(pthread);
|
||||||
|
vTaskDelete(handle);
|
||||||
}
|
}
|
||||||
xSemaphoreGive(s_threads_mux);
|
xSemaphoreGive(s_threads_mux);
|
||||||
ESP_LOGV(TAG, "%s %p EXIT %d", __FUNCTION__, pthread, ret);
|
ESP_LOGV(TAG, "%s %p EXIT %d", __FUNCTION__, pthread, ret);
|
||||||
|
Reference in New Issue
Block a user