Static variable in task after task deletion

when i create a task
xTaskCreate(myTask, “myTask”, THREAD_STACKSIZE, NULL, 2, NULL);

and the task defines a static variable

void myTask(){

  • static int x = 2;*
  • doSomething(&x);*
  • vTaskDelete(NULL);*

Is x still available after deleting the task? Usually it should be still available, but I am not sure if FreeRTOS is doing some additional clean up work, when deleting the task.

Your variable x will be given a fixed location in RAM (that will be shared by all copies of tasks that use the myTask function.

That location will keep its value after the task is deleted.

FreeRTOS has no way to know about that variable, so won’t touch it.

thanks… needed that confirmation.

In case you want a “variable” like errno, which has a different instance in each task, you may think of using Thread Local Storage Pointers

You find an example in ff_stdio.h

It stores a pointer in the TCB ( Task Control Block ). The pointer may point to a real object, or in case of errno, the pointer has a numeric value:

    /* Cast from a numeric value to a pointer. */
    void * pvValue = ( void * ) ( xErrno );