Task context switching issue

04 Sep 2019

Hello all,

I am facing an unexpected behavior while using the Mbed OS kernel in my application software.

Description of Scenario is detailed below: The 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 me know if there is any fix (known bug) related to OS context switching functionality in mbed OS.

Thanks Sagar

10 Sep 2019

Hi Sagar,

Mbed OS has managed it's own sleep thread, if you need do something before idle, you can add a hook function,

https://os.mbed.com/docs/mbed-os/v5.13/apis/kernel-interface-functions.html#kernel-hooks-example

Could you try not using your own sleep thread, instead, using the kernel hook function?

Thanks, Desmond