Delete Semaphore inside task

Dear All, Just a quick question, does it possible to delete semaphore inside task ? my code is working but not quite sure it is safe ? does the semaphore need to be deleted after the Vtask delete (see my code following) void myTask(void const* pArgument) { for (;;) { osSemaphoreWait(xSemaphore, osWaitForever); // do some actions vSemaphoreDelete(xSemaphore); vTaskDelete(NULL); } } Thanks

Delete Semaphore inside task

Deleting a task does not delete the objects created by that task, so yes it is correct to delete the semaphore first.

Delete Semaphore inside task

Thanks Richard

Delete Semaphore inside task

One other comment, putting the vSemaphoreDelete after the call to vTaskDelete(NULL) wouldn’t work, as a call to vTaskDelete(NULL) won’t return, as the calling task no longer exists. It is sort of the the task equivalent to exit() (for that particular task).