AIX Version 4.3 Differences Guide
AIX Version 4.3 Differences Guide
AIX Version 4.3 Differences Guide
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
The user scheduler maintains a runqueue of runnable local pthreads and<br />
dispatches them on available kernel threads. Each kernel thread is represented<br />
in the pthreads library by a virtual processor structure (VP). There is a 1:1<br />
mapping between VPs and kernel threads.<br />
The user scheduler catches a SIGWAITING signal. Applications should not catch<br />
this signal, it is only for system use.<br />
Each time a local pthread is created, terminates, or goes to sleep in the library,<br />
the user scheduler examines the ratio of kernel threads to active and sleeping<br />
user pthreads. If they are not consistent with the required values, then VPs, and<br />
hence, kernel threads, are created or destroyed as required. A VP that is to be<br />
deleted first places the user pthread it was running on to the queue of runnable<br />
pthreads maintained by the library. It then adds itself to the list of zombie VPs,<br />
and marks the underlying kernel thread for termination. The user scheduler<br />
traverses the list of zombie VPs on a regular basis and deletes the redundant VP<br />
structures.<br />
Time slicing of local threads is initiated by the <strong>AIX</strong> scheduler, which sets a flag in<br />
the currently running kernel thread once it has obtained a full timeslice. On return<br />
from the clock tick interrupt handler, if the timeslice flag is set, the thread will call<br />
the user scheduler. The user scheduler places the current local thread on the<br />
local pthreads library runqueue and then selects the highest priority thread to run.<br />
If there are no threads on the run queue, then the current thread continues to run.<br />
The user scheduler controls which pthreads are woken when a pthread event<br />
occurs. For example, when a mutex lock is released. The sleeping pthreads may<br />
have system-wide (global) or process-wide (local) contention scope. The user<br />
scheduler favors pthreads with system-wide scope over those with process-wide<br />
scope, regardless of their priorities. Priority is only used to decide between<br />
pthreads with the same contention scope. If they have the same priority, then the<br />
pthread that has been waiting the longest will be woken first.<br />
When a local pthread makes a system call, it may block in the kernel waiting for a<br />
response from the system call. In this instance, the kernel thread and VP are not<br />
available to run another local pthread.<br />
Consider a process with N+1 local threads, and N VPs, where one thread writes<br />
data to a pipe, and N threads read data from the pipe. The process would<br />
encounter a deadlock situation when the N threads reading from the pipe were<br />
blocked in the kernel. There would be no VP available for the N+1 thread to run<br />
on to write data to the pipe. This situation is avoided by a special check in the<br />
routine that a thread calls when about to block in the kernel. If the thread about to<br />
block is on the only VP of the process that is not already blocked, then the user<br />
scheduler is activated and instructed to create a new VP and kernel thread to run<br />
another local thread.<br />
<strong>4.3</strong>.4 Mutex Locks<br />
In previous versions of <strong>AIX</strong>, when a mutex lock is blocked, a pthread attempting<br />
to get the lock sleeps in the kernel. The internal structure of the mutex lock has<br />
been changed so that the list of threads waiting for the mutex is maintained in the<br />
user address space by the pthreads library. This is to allow the user scheduler to<br />
achieve relatively uniform levels of multiplexing over the remaining pthreads<br />
Application Development and Pthreads 73