Thread, mutex, condition_variable on RA4 ARM Cortex-M33

Hi, we are busy deciding which route to go with these micros and our project. I am trying to port a library from another product and am having a few problem. 

Is it possible to have a C++11 based project that uses std::mutex, std::thread and std::condition_variable etc

It seems the toolchain support it, if the header files are all available, but it is not compiling in the code as getting the following errors below

..\src\JobQueue.cpp:158:27: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
..\src\JobQueue.cpp:158:27: error: 'mutex' is not a member of 'std'

..\src\JobQueue.h:20:1: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
..\src\JobQueue.h:148:22: error: 'thread' is not a member of 'std'

I am building in e2Studio. What am I missing? Do I need to enable these features in the settings/compiler options? Do I need to use an RTOS? Or can I do this on a BareMetal system?

Any advice would be appreciated.


  • You should wrte a C++ wrapper for each RTOS object thar has a C++ api that you will use in your code. Each .cpp and .h will include the ThreadX call using tue C api. So you'll have mutex.cpp, thread.cpp, etc and the corresponding .h file for each. Each cpp will interface to the RTOS app using cpp to c calling conventions.   If you google, you should be able to find this done by others.

    An alternative wpuld be one rtos.cpp/.h that has all the RTOS api's exposed in each method. 

    You can make this wrapper a static class, or singleton.

  • Thanks for the reply. So you are suggestion that there is no current implementation of those libraries for compiler supplies with E2Studio? And I'd have to implement those features myself?

    Is it more normal to just not use the standard C++ libraries and rather just call straight into the RTOS libraries? I was hoping to stick to the standard libraries so that the code can be cross platform.

  • The headers for c++11 concurrency define the interface and operation but the implementation is not provided. Something like this might work -