Which Method Registers A Thread In A Thread Scheduler?
Scheduling of threads involves ii boundary scheduling,
- Scheduling of user level threads (ULT) to kernel level threads (KLT) via lightweight process (LWP) by the application programmer.
- Scheduling of kernel level threads by the system scheduler to perform different unique bone functions.
Lightweight Process (LWP) :
Low-cal-weight process are threads in the user space that acts as an interface for the ULT to access the physical CPU resources. Thread library schedules which thread of a process to run on which LWP and how long. The number of LWP created by the thread library depends on the type of application. In the instance of an I/O spring application, the number of LWP depends on the number of user-level threads. This is considering when an LWP is blocked on an I/O functioning, then to invoke the other ULT the thread library needs to create and schedule another LWP. Thus, in an I/O jump awarding, the number of LWP is equal to the number of the ULT. In the case of a CPU bound application, it depends only on the awarding. Each LWP is attached to a separate kernel-level thread.
In real-time, the first purlieus of thread scheduling is beyond specifying the scheduling policy and the priority. It requires ii controls to be specified for the User level threads: Contention scope, and Allotment domain. These are explained as following below.
1. Contention Scope :
The word contention hither refers to the contest or fight among the User level threads to access the kernel resources. Thus, this control defines the extent to which contention takes identify. It is divers by the application programmer using the thread library. Depending upon the extent of contention information technology is classified as Process Contention Telescopic and System Contention Scope.
- Process Contention Scope (PCS) –
The contention takes place among threads within a same process. The thread library schedules the high-prioritized PCS thread to admission the resource via available LWPs (priority every bit specified by the awarding developer during thread creation). - Organization Contention Scope (SCS) –
The contention takes place among all threads in the system. In this case, every SCS thread is associated to each LWP by the thread library and are scheduled by the system scheduler to access the kernel resources.In LINUX and UNIX operating systems, the POSIX Pthread library provides a function Pthread_attr_setscope to define the type of contention scope for a thread during its creation.
int Pthread_attr_setscope(pthread_attr_t *attr, int scope)
- The commencement parameter denotes to which thread within the process the scope is defined.
The 2nd parameter defines the scope of contention for the thread pointed. It takes two values.
PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_PROCESS
- If the scope value specified is not supported by the organisation, then the office returns ENOTSUP.
ii. Allotment Domain :
The allocation domain is a set of one or more resource for which a thread is competing. In a multicore arrangement, at that place may exist ane or more allocation domains where each consists of one or more cores. One ULT can be a part of 1 or more resource allotment domain. Due to this high complexity in dealing with hardware and software architectural interfaces, this control is non specified. Merely by default, the multicore system volition have an interface that affects the allocation domain of a thread.
Consider a scenario, an operating system with three procedure P1, P2, P3 and 10 user level threads (T1 to T10) with a single resource allotment domain. 100% of CPU resource will be distributed among all the three processes. The corporeality of CPU resources allocated to each process and to each thread depends on the contention scope, scheduling policy and priority of each thread defined by the application programmer using thread library and as well depends on the arrangement scheduler. These User level threads are of a different contention scope.
In this case, the contention for allocation domain takes place as follows,
- Procedure P1:
All PCS threads T1, T2, T3 of Procedure P1 will compete among themselves. The PCS threads of the same process can share one or more LWP. T1 and T2 share an LWP and T3 are allocated to a separate LWP. Betwixt T1 and T2 allocation of kernel resources via LWP is based on preemptive priority scheduling by the thread library. A Thread with a high priority volition preempt depression priority threads. Whereas, thread T1 of process p1 cannot preempt thread T3 of process p3 even if the priority of T1 is greater than the priority of T3. If the priority is equal, and then the allotment of ULT to available LWPs is based on the scheduling policy of threads by the system scheduler(non by thread library, in this case). - Procedure P2:
Both SCS threads T4 and T5 of process P2 will compete with processes P1 as a whole and with SCS threads T8, T9, T10 of process P3. The system scheduler volition schedule the kernel resources amid P1, T4, T5, T8, T9, T10, and PCS threads (T6, T7) of process P3 because each as a separate process. Here, the Thread library has no control of scheduling the ULT to the kernel resource. - Procedure P3:
Combination of PCS and SCS threads. Consider if the system scheduler allocates 50% of CPU resources to procedure P3, and so 25% of resource is for process scoped threads and the remaining 25% for system scoped threads. The PCS threads T6 and T7 will exist allocated to access the 25% resources based on the priority by the thread library. The SCS threads T8, T9, T10 will divide the 25% resource amidst themselves and access the kernel resources via separate LWP and KLT. The SCS scheduling is by the organisation scheduler.
Annotation:
For every arrangement telephone call to access the kernel resources, a Kernel Level thread is created and associated to separate LWP by the system scheduler.
Number of Kernel Level Threads = Full Number of LWP Total Number of LWP = Number of LWP for SCS + Number of LWP for PCS Number of LWP for SCS = Number of SCS threads Number of LWP for PCS = Depends on application developer
Here,
Number of SCS threads = 5 Number of LWP for PCS = 3 Number of SCS threads = five Number of LWP for SCS = five Full Number of LWP = viii (=5+3) Number of Kernel Level Threads = 8
Advantages of PCS over SCS :
- If all threads are PCS, then context switching, synchronization, scheduling everything takes identify inside the userspace. This reduces system calls and achieves better performance.
- PCS is cheaper than SCS.
- PCS threads share one or more bachelor LWPs. For every SCS thread, a separate LWP is associated.For every organization call, a split KLT is created.
- The number of KLT and LWPs created highly depends on the number of SCS threads created. This increases the kernel complication of handling scheduling and synchronization. Thereby, results in a limitation over SCS thread creation, stating that, the number of SCS threads to exist smaller than the number of PCS threads.
- If the organisation has more than one resource allotment domain, then scheduling and synchronization of resources becomes more ho-hum. Issues arise when an SCS thread is a function of more one allocation domain, the organization has to handle n number of interfaces.
The second boundary of thread scheduling involves CPU scheduling by the system scheduler. The scheduler considers each kernel-level thread every bit a split up process and provides access to the kernel resources.
?list=PLqM7alHXFySEJYFqrpxG4eTbUAiX6jD0Y
Which Method Registers A Thread In A Thread Scheduler?,
Source: https://www.geeksforgeeks.org/thread-scheduling/
Posted by: williamsabad1979.blogspot.com
0 Response to "Which Method Registers A Thread In A Thread Scheduler?"
Post a Comment