Multiple task creation with same parameters

Is there any issue if a task is created again in a loop? System crashes? all of the task are created if heap is enough? or only one is created?

example:

while(1)
{
xTaskCreate(
      xTask_MANUAL_MODE,
      "xTask_MANUAL_MODE",
      8000,
      (void *)&(xBit_sources_on),
      4,
      &xTask_MANUAL_MODE_HANDLE);
}

If you call xTaskCreate in an infinite loop, eventually you are going to exhaust heap and task creation will fail. You can check the return value of xTaskCreate to know whether or not the task creation was successful. What are you trying to achieve?

Thanks.

Hello Gaurav, thanks for your reply.

I am creating a task from another one like this:

static void CREATOR_TASK(void *pvParameters)
{
xTaskCreate(
xTask_CREATED_TASK,
“xTask_CREATED_TASK”,
8000,
(void *)&(xBit_sources_on),
4,
&xTask_CREATED_TASK_HANDLE);
}

static void CREATED_TASK(void *pvParameters)
{
vTaskdelay(1000);
}

On my code, CREATOR_TASK is deleted and created from external conditions so it can happen anytime, even when CREATED_TASK is still in the delay.

As you see, it is possible that CREATOR_TASK creates another one with the same name, handle and function name.

My question is: is there going to be an issue and do I have to control this underided behavior?

Thank you in advance

First, your CREATED_TASK has a problem that it returns, which tasks are not supposed to do. If it is done, it needs to delete itself, which, at least in general, doesn’t happen on a task returning.

CREATOR_TASK, if it is also a task has the same problem.

There is nothing wrong with creating multiple tasks from that same function, even with the same name (that can be confusing to you, but the name isn’t used for anything but reporting by FreeRTOS). FreeRTOS keeps track of the different tasks because they have different handles. Now, you put the new task handle into the same variable as the old one, so YOU have lost access to the old task (unless you have copied that handle somewhere), but FreeRTOS still is keeping the values seperate.

Hello Richard, thank you for your reply.

The problems you mentioned about returning tasks, you are right, i wrote the example without them but i have them clear, thanks for noticing it.

And you gave me the answer to my question, thank you for your help.