Thread-specific data for thread-specific properties and threads
One, POSIX thread properties
The POSIX line threading defines the Thread Property object pthread_attr_t, which encapsulates the thread properties that the creator of the thread can access and modify. Mainly includes the following properties:
1. Scope (SCOPE)
2. Stack sizes (stack size)
3. Stack Address
4. Priority level (priority)
5. Separation status (detached state)
6. Scheduling Strategies and parameters (scheduling policy and parameters)
A thread Property object can be associated with a thread or multiple line threads relative. When you use a thread Property object, it is a configuration of thread and thread group behavior. All the threads that use the Property object will have all the properties defined by the Property object. Although they share property objects, they maintain separate thread IDs and registers.
Threads can compete for resources within two competing domains:
1. Process domain (procedure scope): With other threads in the same process
2. System scope: With all threads in the system
Scope properties describe which threads a particular thread will compete with for resources. A thread with a system domain will compete with all the system domain threads in the system to prioritize the processor resources for scheduling.
Detach threads are threads that do not need to be synchronized with other threads in the process. In other words, no thread waits for the detach thread to exit the system. Therefore, once the thread exits, its resources, such as the thread ID, can be reused immediately.
The layout of the thread is embedded in the layout of the process. Processes have code snippets, data segments, and stack segments, while threads share code snippets and data segments with other threads in the process, and each thread has its own stack segment, which is allocated in the stack segment of the process address space. The dimensions of the line stacks are set when the thread is created. If there is no setting at the time of creation, the system will specify a default value, the size of which depends on the specific system.
The thread properties and their implications that can be set in the POSIX thread Property object are shown in the following table:
Function |
Property |
Meaning |
int Pthread_attr_setdetachstate (pthread_attr_t* attr, int detachstate) |
Detachstate |
The Detachstate property controls whether a thread is separable. |
int Pthread_attr_setguardsize (pthread_attr_t* attr, size_t guardsize) |
Guardsize |
Guardsize property to set the overflow of a new created line stacks Protected Area Size |
int pthread_attr_setinheritsched (pthread_attr_t* attr, int inheritsched) |
Inheritsched |
Inheritsched decide how to set up a newly created Scheduling Properties for Threads |
int Pthread_attr_setschedparam (Pthread_attr_t* attr, const struct sched_param* restrict param) |
Param |
Param used to set the priority of the newly created thread |
int Pthread_attr_setschedpolicy (pthread_attr_t* attr, int policy) |
Policy |
Policy is used to set the schedule to create the thread first Strategy |
int Pthread_attr_setscope (Pthread_attr_t* attr, int contentionscope) |
Contentionscope |
Contentionscope used to set up a new creation line Scope of the process |
int Pthread_attr_setstack (pthread_attr_t* attr, void* stackader, size_t stacksize) |
Stackader StackSize |
Both determine the base site of the line stacks And the minimum size of the stack (in bytes) |
int pthread_attr_setstackaddr (pthread _attr_t* attr, Void*stackader) |
Stackader |
Stackader determines the base address of the stack of newly created threads |
int Pthread_attr_setstacksize (pthread_attr_t* attr, size_t stacksize)
StackSize determines the minimum size of the stack for the newly created thread