TSDuck Version 3.15-964 (TSDuck - The MPEG Transport Stream Toolkit)
ts::ThreadAttributes Class Reference

Set of attributes for a thread object (ts::Thread). More...

Public Member Functions

 ThreadAttributes ()
 Default constructor (all attributes have their default values).
 
bool getDeleteWhenTerminated () const
 Get the delete when terminated flag for the thread. More...
 
int getPriority () const
 Get the priority for the thread. More...
 
size_t getStackSize () const
 Get the stack size in bytes for the thread. More...
 
ThreadAttributessetDeleteWhenTerminated (bool dwt)
 Set the delete when terminated flag for the thread. More...
 
ThreadAttributessetPriority (int priority)
 Set the priority for the thread. More...
 
ThreadAttributessetStackSize (size_t size)
 Set the stack size in bytes for the thread. More...
 

Static Public Member Functions

static int GetHighPriority ()
 Get a high priority for a thread in this context of the operating system. More...
 
static int GetLowPriority ()
 Get a low priority for a thread in this context of the operating system. More...
 
static int GetMaximumPriority ()
 Get the maximum priority for a thread in this context of the operating system. More...
 
static int GetMinimumPriority ()
 Get the minimum priority for a thread in this context of the operating system. More...
 
static int GetNormalPriority ()
 Get the normal priority for a thread in this context of the operating system. More...
 

Detailed Description

Set of attributes for a thread object (ts::Thread).

Member Function Documentation

◆ setStackSize()

ThreadAttributes& ts::ThreadAttributes::setStackSize ( size_t  size)
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.

Parameters
[in]sizeStack size in bytes.
Returns
A reference to this object.

◆ getStackSize()

size_t ts::ThreadAttributes::getStackSize ( ) const
inline

Get the stack size in bytes for the thread.

Returns
The stack size in bytes for the thread. When zero is returned, this means that the default stack size for this operating system will be used.

◆ setDeleteWhenTerminated()

ThreadAttributes& ts::ThreadAttributes::setDeleteWhenTerminated ( bool  dwt)
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:

  • The ts::Thread object must be dynamically allocated using the new operator.
  • Once the thread execution is started, i.e. after invoking ts::Thread::start(), the ts::Thread object must no longer be referenced from other executing thread.

The delete when terminated flag is especially useful to launch dynamically allocated background threads and forget about them.

Parameters
[in]dwtDelete when terminated flag for the thread.
Returns
A reference to this object.

◆ getDeleteWhenTerminated()

bool ts::ThreadAttributes::getDeleteWhenTerminated ( ) const
inline

Get the delete when terminated flag for the thread.

Returns
The delete when terminated flag for the thread.
See also
setDeleteWhenTerminated()

◆ setPriority()

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.

Thread priorities on Microsoft Windows

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.

Thread priorities on Linux

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:

sudo chrt -f 50 /path/to/executable arguments ...

The following command displays the detailed priorities and scheduling policies of all processes and threads:

ps -m -o pid,lwp,euser,pcpu,pmem,vsz,cls,pri,rtprio,cmd -a
Parameters
[in]priorityThe 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.
Returns
A reference to this object.

◆ getPriority()

int ts::ThreadAttributes::getPriority ( ) const
inline

Get the priority for the thread.

Returns
The priority for the thread.
See also
setPriority()

◆ GetMinimumPriority()

static int ts::ThreadAttributes::GetMinimumPriority ( )
inlinestatic

Get the minimum priority for a thread in this context of the operating system.

Returns
The minimum priority for a thread.
See also
setPriority()

◆ GetLowPriority()

static int ts::ThreadAttributes::GetLowPriority ( )
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().

Returns
A "low" priority for a thread.
See also
setPriority()

◆ GetNormalPriority()

static int ts::ThreadAttributes::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.

Returns
The normal priority for a thread.
See also
setPriority()

◆ GetHighPriority()

static int ts::ThreadAttributes::GetHighPriority ( )
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().

Returns
A "high" priority for a thread.
See also
setPriority()

◆ GetMaximumPriority()

static int ts::ThreadAttributes::GetMaximumPriority ( )
inlinestatic

Get the maximum priority for a thread in this context of the operating system.

Returns
The maximum priority for a thread.
See also
setPriority()

The documentation for this class was generated from the following file: