LRID
LRID

Reputation: 55

Using static functions within a duplicated FreeRtos Task

I am using FreeRtos and have a Task that I am using multiple times. I am calling static functions within the Task. During the multiple uses of this task, will the static functions be overwritten with one another's data or cause some type of issue? Eg...

static int addSomeNumbers(int x)
{
   int num1 = 4;
   int num2 = 83;
   int num3 = 65;
   return x+num1+num2+num3;
}

void SomeTask(void *pvParameters)
{
  int localInt = *(int *) pvParameters;
  addSomeNumbers(localInt);
  //continue
}

I use this Task three times

xTaskCreate(SomeTask, "SomeTask0", stackDepth, someNumber0, ...)
xTaskCreate(SomeTask, "SomeTask1", stackDepth, someNumber1, ...)
xTaskCreate(SomeTask, "SomeTask2", stackDepth, someNumber2, ...)

The problem I am running into, is that the data I see coming out of each Task is not consistent. It seems that the second Task sometimes is using the first task's data within addSomeNumbers and so on. Any way to prevent this?

Upvotes: 1

Views: 591

Answers (1)

HelpingHand
HelpingHand

Reputation: 1468

I don't believe this is the case.

Static functions are only about the visibility scope of the function, but not about the storage class of variables used therein.

If this is your actual code (and you haven't declared num1 etc. as static int, the nums will be re-allocated on each task stack, and shall not see "each other" (unless you managed to corrupt the kernel by some unrelated error behaviour...).

Upvotes: 2

Related Questions