vTaskDelete() while select()

Franck.f
Posts: 5
Joined: Mon Jan 13, 2025 8:00 am

vTaskDelete() while select()

Postby Franck.f » Mon Mar 17, 2025 7:36 pm

Is it ok to delete a task (vTaskDelete) that is blocked in a select() call ?

Sprite
Espressif staff
Espressif staff
Posts: 10651
Joined: Thu Nov 26, 2015 4:08 am

Re: vTaskDelete() while select()

Postby Sprite » Tue Mar 18, 2025 1:56 am

I don't think so. In general, it's good practice to only use vTaskDelete to make a task stop itself. If you delete another task, it may be in a state where it took some resource (for instance, malloc()'ed a temporary variable somewhere) and deleting the task will leak that resource.

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: vTaskDelete() while select()

Postby MicroController » Tue Mar 18, 2025 2:26 pm

Unfortunately, FreeRTOS doesn't provide any clean/safe/defined way to interrupt a blocking function like select().
There's xTaskAbortDelay(), which would be up to the task, but it's implemented with an inherent race condition, so not safe/reliable.

The HTTPD component works around the issue by using an additional (local) socket just to be able to get another task out of blocking in a select().

Who is online

Users browsing this forum: Bing [Bot], ChatGPT-User, PetalBot and 2 guests