usStackDepth not showing any effect in POSIX simulation layer

On Posix Simulation Layer, I’m creating task using:

xTaskCreate(task_1, "Task-1", 100, "\nHello world from task1", 1, Task1_handle);


static void task_1(void* parameter) {
    int i = 0;
    printf("%s\n", (char*) parameter);
    long a[250];
    for (int i = 0; i < 250; i++) {
        a[i] = i+i;
        printf("%lu ", a[i]);
    while(1) {

I performed this experiment with heap_1.c, heap_2.c as well as with heap_4.c

Problem: I was expecting it to throw some error as my task_1 was using more memory than being allocated in the xTaskCreate API.
But my task ran smoothly. Any leads will be appreciated. I’m a beginner on FreeRTOS.
PS: I’m not using any board. I’m experimenting on the Posix Simulation layer.

Hello bluechip!

This is due to the Posix Simulator task stack having a restriction on the true minimum size. If you read the final section on this page it mentions…

A limitation exists for the minimal stack size that can be created. This limitation is platform dependent and is equal to PTHREAD_STACK_MIN…As a workaround, always pass a stack of size PTHREAD_STACK_MIN if the desired stack is less than PTHREAD_STACK_MIN when running on a Posix port.

It is almost certain that PTHREAD_STACK_MIN is larger than the stack size of 100 supplied which explains why you’re not seeing stack failures.

1 Like

For more on why this is the minimum stack size, see the “Principle of Operation” section on this page.

1 Like

Thanks a lot! This explains.

No problem! If you’re happy with the answer, feel free to mark my comment as the solution.