Sharing Data Locally on an RT Target (RT Module)
- Updated2023-02-21
- 2 minute(s) read
After dividing tasks in an application into threads of different priorities, you might need to communicate between different threads on the RT target. Use global variables, thread safe variables, and thread safe queues to share data between threads running on an RT target.
You can use global variables to access and pass small amounts of data between threads, such as from a time-critical thread to a lower priority thread. Global variables can share data smaller than 32-bits, such as scalar data, between threads deterministically. However, global variables of larger data types require locking to prevent simultaneous access and therefore become shared resources that you must use carefully from deterministic code.
Thread safe variables combine the reading or writing of a variable with the necessary acquiring and releasing of a lock. The lock provides safe access from multiple threads. Due to the locking aspect, thread safe variables are shared resources that you must use carefully from deterministic code. The Utility Library provides functions and macros to use thread safe variables in your application.
Global variables and thread safe variables are lossy forms of communication, meaning that one thread can overwrite the data before the other thread reads the data. Tasks in a lower priority thread might not have enough processor time to read the data before other tasks in a different thread overwrite the data.
Thread safe queues provide an efficient mechanism for passing multiple data values between threads. The thread safe queue is optimized such that one thread can write to the queue while another thread reads from the queue. The Utility Library provides functions to use thread safe queues in your application.
![]() |
Note Do not use the OPT_TSQ_DYNAMIC_SIZE option for a thread safe queue that is accessed from deterministic code. This option can cause the queue to allocate memory during use, which can affect determinism. |
