Real-Time Embedded Multithreading: Using ThreadX and ARM

You have investigated several aspects of threads in previous chapters, including their purpose, creation, composition, and usage. In this chapter, you will explore all the services that directly affect threads. To get started, you will review the purpose as well as the contents of the Thread Control Block. You will also examine each of the thread services, with an emphasis on the features and capabilities of each service.
The Thread Control Block (TCB) [26] is a structure used to maintain the state of a thread during run-time. It is also used to preserve information about a thread when a context switch becomes necessary. Figure 6.1 contains many of the fields that comprise the TCB.
A TCB can be located anywhere in memory, but it is most common to make the Control Block a global structure by defining it outside the scope of any function. [27] Locating the Control Block in other areas requires a bit more care, as is the case for all dynamically allocated memory. If a Control Block were allocated within a C function, the memory associated with it would be allocated on the calling thread s stack. In general, avoid using local storage for Control Blocks because once the function returns, then its entire local variable stack space is released regardless of whether another thread is using it for a Control Block.
| Field | Description | Field | Description | |
|---|---|---|---|---|
| tx_thread_id | Control Block ID | tx_state | Thread s execution state | |
| tx_run_count | Thread s run counter | tx_delayed_suspend |