Delete Semaphore inside task

delphes wrote on Wednesday, June 13, 2018:

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 (;:wink: {
osSemaphoreWait(xSemaphore, osWaitForever);
// do some actions


rtel wrote on Wednesday, June 13, 2018:

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

delphes wrote on Wednesday, June 13, 2018:

Thanks Richard

richard_damon wrote on Thursday, June 14, 2018:

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).