![]() |
TSDuck v3.39-3843
MPEG Transport Stream Toolkit
|
Set of attributes for a thread object (ts::Thread). More...
#include <tsThreadAttributes.h>
Public Member Functions | |
ThreadAttributes () | |
Default constructor (all attributes have their default values). | |
bool | getDeleteWhenTerminated () const |
Get the delete when terminated flag for the thread. | |
bool | getExitOnException () const |
Get the exit on exception flag for the thread. | |
UString | getName () const |
Get the thread name. | |
int | getPriority () const |
Get the priority for the thread. | |
size_t | getStackSize () const |
Get the stack size in bytes for the thread. | |
ThreadAttributes & | setDeleteWhenTerminated (bool dwt) |
Set the delete when terminated flag for the thread. | |
ThreadAttributes & | setExitOnException (bool eoe) |
Set the exit on exception flag for the thread. | |
ThreadAttributes & | setName (const UString &name) |
Set the thread name. | |
ThreadAttributes & | setPriority (int priority) |
Set the priority for the thread. | |
ThreadAttributes & | setStackSize (size_t size) |
Set the stack size in bytes for the thread. | |
Static Public Member Functions | |
static int | GetHighPriority () |
Get a high priority for a thread in this context of the operating system. | |
static int | GetLowPriority () |
Get a low priority for a thread in this context of the operating system. | |
static int | GetMaximumPriority () |
Get the maximum priority for a thread in this context of the operating system. | |
static int | GetMinimumPriority () |
Get the minimum priority for a thread in this context of the operating system. | |
static int | GetNormalPriority () |
Get the normal priority for a thread in this context of the operating system. | |
Set of attributes for a thread object (ts::Thread).
|
inline |
Set the thread name.
This is just an informational name, depending on the operating system.
[in] | name | Thread name. |
|
inline |
Get the thread name.
|
inline |
Set the stack size in bytes for the thread.
It is guaranteed that specifying zero as the stack size of a thread will in fact use the default stack size value for the operating system.
[in] | size | Stack size in bytes. |
|
inline |
Get the stack size in bytes for the thread.
|
inline |
Set the delete when terminated flag for the thread.
The delete when terminated flag is used to automatically delete ts::Thread objects when the thread execution terminates. More precisely, when the ts::Thread::main() method terminates, the delete
operator is invoked on the ts::Thread object.
The default value for this flag is false
.
To set the delete when terminated flag to true
, the following condition are required:
new
operator. The delete when terminated flag is especially useful to launch dynamically allocated background threads and forget about them.
[in] | dwt | Delete when terminated flag for the thread. |
|
inline |
Get the delete when terminated flag for the thread.
|
inline |
Set the exit on exception flag for the thread.
The exit on exception flag is used to automatically exit the application when the thread terminates on exception.
The default value for this flag is false
.
[in] | eoe | Exit on exception flag for the thread. |
|
inline |
Get the exit on exception flag for the thread.
ThreadAttributes & ts::ThreadAttributes::setPriority | ( | int | priority | ) |
Set the priority for the thread.
This class tries to present a system independent view of thread priorities. A priority is simply an int
value. The higher the value is, the more priority the thread have.
The minimal and maximum priorities are given by GetMinimumPriority() and GetMaximumPriority(). The default priority is given by GetNormalPriority().
The number of available priorities depends on the operating system and, sometimes, on the execution context of the operating system.
On Microsoft Windows, there are 7 different priorities. They are named IDLE, LOWEST, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGHEST and TIME_CRITICAL in the Microsoft literature. They are represented using 0 to 6 in this class.
On Linux, the number of priorities depends on the scheduling policy of the current thread. See the man page of sched_setscheduler(2)
for more details.
The default scheduling policy (other, also known as TS for Time Sharing) assigns the same base priority to all processes and threads, regardless of the thread priorities which are set in the application. In this scheduling policy, only one priority is available, the same for all threads.
To run a real-time process with discriminating priorities, it is necessary to run as root and start the command with a non-default scheduling policy. For instance, the following command runs an application using FIFO scheduling policy with a base priority 50:
The following command displays the detailed priorities and scheduling policies of all processes and threads:
[in] | priority | The priority for the thread. If the specified priority is lower than the operating system minimum priority, the actual priority is set to the minimum value. Similarly, if the specified priority is greater than the operating system maximum priority, the actual priority is set to the maximum value. |
|
inline |
|
inlinestatic |
Get the minimum priority for a thread in this context of the operating system.
|
inlinestatic |
Get a low priority for a thread in this context of the operating system.
This is a priority which is typically between GetMinimumPriority() and GetNormalPriority().
|
inlinestatic |
Get the normal priority for a thread in this context of the operating system.
This is the priority of a thread which is neither advantaged nor disadvantaged.
|
inlinestatic |
Get a high priority for a thread in this context of the operating system.
This is a priority which is typically between GetNormalPriority() and GetMaximumPriority().
|
inlinestatic |
Get the maximum priority for a thread in this context of the operating system.