Running more than one task on a single core is multitasking or multi-threading. Running task on differing cores is multiprocessing.
The issue with using code in loop() under freeRTOS is that when loop() runs if there is no code in loop() housekeeping chores are ran, like memory cleanup. If loop() has code that code may run instead. As the programs gets more complicated loop() has the lowest priority. Any code in loop() ins NOT guaranteed to run under freeRTOS.
It depends on the implementation of delay(). In an RTOS a task should release its core while waiting, so that your example would run on a single core controller without blocking each other.
How will it look if you replace the delay() by a loop waiting for the time interval to elapse?
TaskHandle_t Core0Task;
TaskHandle_t Core1Task;
void setup()
{
Serial.begin(115200);
// Set up Core 0 task handler
xTaskCreatePinnedToCore(
codeForCore0Task,
"Core 0 task",
10000,
NULL,
1,
&Core0Task,
0);
// Set up Core 1 task handler
xTaskCreatePinnedToCore(
codeForCore1Task,
"Core 1 task",
10000,
NULL,
1,
&Core1Task,
1);
}
void loop()
{
Serial.print("Main loop on core ");
Serial.println(xPortGetCoreID());
unsigned long start = millis();
while (millis() - start < 100);
}
void codeForCore0Task(void *parameter)
{
for (;;)
{
Serial.print("Task 0 loop on core ");
Serial.println(xPortGetCoreID());
unsigned long start = millis();
while (millis() - start < 100);
}
}
void codeForCore1Task(void *parameter)
{
for (;;)
{
Serial.print("Task 1 loop on core ");
Serial.println(xPortGetCoreID());
unsigned long start = millis();
while (millis() - start < 100);
}
}
Results were similar...
22:51:23.912 -> Task 0 loop on core 0
22:51:23.912 -> Main loop on core 1
22:51:23.912 -> Task 1 loop on core 1
22:51:24.016 -> Task 0 loop on core 0
22:51:24.016 -> Main loop on core 1
22:51:24.016 -> Task 1 loop on core 1
22:51:24.088 -> Task 0 loop on core 0
22:51:24.123 -> Main loop on core 1
22:51:24.123 -> Task 1 loop on core 1
22:51:24.191 -> Task 0 loop on core 0
22:51:24.191 -> Main loop on core 1
22:51:24.191 -> Task 1 loop on core 1
And then every 6 seconds or so it crashes with...
22:51:30.865 -> E (11876) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
22:51:30.865 -> E (11876) task_wdt: - IDLE0 (CPU 0)
22:51:30.865 -> E (11876) task_wdt: Tasks currently running:
22:51:30.865 -> E (11876) task_wdt: CPU 0: Core 0 task
22:51:30.865 -> E (11876) task_wdt: CPU 1: Core 1 task
22:51:30.865 -> E (11876) task_wdt: Aborting.
22:51:30.865 -> abort() was called at PC 0x400e111f on core 0
And putting code in loop(), a poor coding practice, when using freeRTOS in the Arduino IDE will cause issues. Code in loop() is not guaranteed to run under freeRTOS.
If you're not going to have code in the loop() function anyway, there's no point in allowing the task that calls the loop() function to continue running.
Which can cause issues. When vTaskDelete(null) is ran freeRTOS removes the calling task. One might see where if loop() is removed as a task but then loop() is called there would be an issue.