Search code examples
c++multithreadingstm32freertoskeil

how to work with std::thread on freeRTOS?


I'm using freeRTOS on an stm32f407 with keil ide and arm compiler version 6 and g++17 and I don't like to work with freeRTOS threading APIs. instead, I want to work with std::thread c++ native library. but when I include #include <thread>, keil throws this error: error: <thread> is not supported on this single threaded system.

what is the problem?

when I have freeRTOS it means my platform is not single-threaded, so why keil throws this error?


Solution

  • Keil throws that error because you are linking your application against a library that does not support the API.

    There's a freeRTOS POSIX threading wrapper you can possibly evaluate to use, or you could create another abstraction layer on top of CMSIS OS API.

    There is also a C++ wrappers project, freeRTOS-addons, that provides a convenient set of classes/APIs, but it has been inactive for years now.

    Before going for a wrapper, one must evaluate why using an RTOS at all if its features of determinism and tasks priority mechanisms will not be used as equal priority tasks will share CPU time. Yet, of course, there are other benefits.