5 years, 2 months ago.

Task context switching in Mbed OS

Hello Mbed Team,

We are facing unexpected behavior while using the Mbed OS kernel with our application software.

Description of Scenario is detailed below: Our application program uses mbed OS kernel module (mbed-os-5.13.4). The application runs in a multi-threaded environment with 14 active threads. Each thread is assigned different thread priorities with different stack sizes. One of the thread called as sleep thread in the application is idle thread and shall be active only when no other threads are actively running. The priority assigned to this sleep thread is "osPriorityIdle(1)". Other threads are assigned higher priorities in range 56-45.

Issue observed in sleep thread: When switching to/from sleep thread , the task context of thread is not saved/restored properly by the mbed OS. Due to this, the expected values of variables are corrupted and results in unexpected behavior of the sleep thread and hence application. Even changing the priority of the sleep thread to other value like 45 , results in same behavior/issue.

Please let us know if there is any fix (known bug) related to OS context switching functionality in mbed OS.

Thanks Sagar

1 Answer

5 years, 2 months ago.

Any chance you're running out of memory with 14 threads running? Did you configure each thread to use a smaller footprint of memory?

The reason I ask is that there is no memory checking and if you run out you probably will observe the behavior you are seeing.

You can try building up a test case to prove this out by starting with the idle thread and then adding one task at a time until it breaks.

Thanks for the reply.

I have made it from 14->8 threads execution. For time being not starting other 6 threads. Still the issue persists.

Also each thread is allocated bigger size of stack memory deliberately and more than 20KB heap is assigned (for internal kernal usage if any). My application does not need heap memory at all (since every memory is predefined and hence statically allocated in RAM).

posted by sagar sujathan 06 Sep 2019