topics that matter; ideas worth sharing

share a tip, submit a link, add something new

Scheduling in the user threads library, Part 2

March 16, 2001, 05:47 PM —  Unix Insider — 

Last month, we saw that the threads library implements a relatively simple queue of runnable threads, in which threads at the same user-thread priority are maintained on a linked list. Each list of threads is rooted in an array, and there's one array location for each of the 128 (0 through 127) possible thread priorities. User-thread scheduling is accomplished by the unbound threads calling into preemption and dispatcher routines at various points in the code path, such as when a thread blocks on a user-defined synchronization object.


User threads can inherit their priority from their calling thread. This thread will have a default value of zero, though it can be explicitly increased with a pthread_attr_setschedparam(3thr) or pthread_setschedparam(3thr) call. The difference between the two interfaces can be summarized as follows:


pthread_attr_setschedparam(3thr) makes use of an attribute object (see last month's column for a list of thread attributes), which can be set and passed as an argument to a pthread_create(3thr) call. Once the thread has been created, attribute changes can't be made, because there's no runtime linkage between a user thread and an attribute object.


pthread_setschedparam(3thr) takes a thread ID as an argument, and can alter the priority of a running thread. For that reason, the desired attributes of a thread must be determined prior to the thread's creation, as most of them cannot be changed once the thread has been created.


The priorities of Solaris threads can be altered using either the thr_setprio(3thr) or thr_getprio(3thr) interface to retrieve the threads' priority.


Three possible scheduling policies are available for POSIX threads. The default policy is SCHED_OTHER, which is defined as implementation-specific. In Solaris, it provides for a new thread inheriting the scheduling policy of the creator thread. By default, it provides timeshare or interactive scheduling behavior. Note that POSIX threads provide an attribute allowing for a thread to ignore inherited scheduling policy. (See pthread_attr_setinheritsched(3thr).) We'll revisit that idea in a moment. For now, assume the default behavior if inheriting scheduling policy.


POSIX also provides for SCHED_FIFO (first in, first out) and SCHED_RR (round robin) policies. Solaris support for these policies first appeared in Solaris 7. Both scheduling policies will cause the newly created thread to be placed in the realtime scheduling class if the thread is bound. In other words, if the contentionscope attribute is PTHREAD_SCOPE_SYSTEM (which is how one creates bound threads using POSIX interfaces), the threads library issues a priocntl(2) system call internally to place the bound pthread in the realtime scheduling class. As such, the effective user identification (UID) of the user executing the code must be root, as only root can place processes and threads in the realtime scheduling class.


The difference between the two policies when dealing with bound threads is somewhat subtle. The documentation indicates that a SCHED_FIFO thread will execute to completion unless it's preempted by a higher priority

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff
Featured Sponsor

Get a broad understanding of important regulations and how you can make sure your site is in adherence.





Learn how VeriSign SGC-enabled SSL Certificates can help improve site security and customer confidence in the free white paper, "How to Offer the Strongest SSL Encryption." In this paper you will learn the differences between weak and strong encryption and what they mean for your site's performance.

Get VeriSign's free white paper: "The Latest Advancements in SSL Technology" and learn about the benefits of strong SSL encryption, Extended Validation (EV) SSL and security trust marks and what these SSL offerings can do for your site.

Now with Extended Validation (EV) SSL available from VeriSign, you can show your customers that they can trust your site. Learn about EV SSL benefits in this free VeriSign white paper.

More Resources