EtcPal
0.4.1
ETC Platform Abstraction Layer (EtcPal)
|
View other versions:
|
C++ utilities for the thread (Threading) module.
Provides a thread class Thread which is similar to std::thread, with the key advantage that it will work on any threaded platform that EtcPal is ported for, including the embedded RTOS platforms. If your application or library does not need to run on these platforms, consider using std::thread instead (or in >= C++20, std::jthread, which more closely matches the behavior of this class).
To start the thread with default parameters, you can use the constructor:
The value constructor will throw an etcpal::Error object if the thread fails to start for any reason. To avoid an exception-handling approach, you can default-construct and use the Start() function:
This approach also lets you set non-default thread parameters before starting; method-chaining syntax is available on these setters:
Pass arguments to your thread function, which will be stored on the heap:
You can even use lambdas for quick-and-dirty operations:
The Thread class also provides static Sleep() functions, which can be used as a platform-neutral sleep.
IMPORTANT NOTE FOR RTOS USERS: The EtcPal threading API does not initialize the scheduler on real-time systems (e.g. it does not call vTaskStartScheduler() on FreeRTOS or _mqx() on MQX). The application writer is responsible for managing the interaction between starting the scheduler and starting EtcPal threads, just like when starting native RTOS tasks.
Data Structures | |
class | Thread |
A thread class, modeled after std::thread. More... | |