OS Unit 2
OS Unit 2
Combined Approach
• Some operating systems provide a combined ULT/KLT facility
• In a combined system, thread creation is done
completely in user space, as is the bulk of the scheduling and
synchronization of threads within an application
• The multiple ULTs from a single application are mapped onto
some number of KLTs
• The programmer may adjust the number of KLTs for a
particular application and processor to achieve the best
overall results
• In a combined approach, multiple threads within the same
application can run in parallel on multiple processors, and a blocking system call need
not block the entire process.
• Solaris is a good example of an OS using this combined approach
Solaris Thread
Solaris implements multilevel thread support designed to provide considerable flexibility in
exploiting processor resources.
Multithreaded Architecture
Solaris makes use of four separate thread-related concepts:
Process: This is the normal UNIX process and includes the user’s address space, stack, and
process control block.
User-level threads: Implemented through a threads library in the address space of a process,
these are invisible to the OS. A user-level thread (ULT)7 is a user-created unit of execution
within a process.
Lightweight processes: A lightweight process (LWP) can be viewed as a mapping between ULTs
and kernel threads. Each LWP supports ULT and maps to one kernel thread. LWPs are scheduled
by the kernel independently and may execute in parallel on multiprocessors.
Kernel threads: These are the fundamental entities that can be scheduled and dispatched to run
on one of the system processors.
Race Condition
A race condition occurs when multiple processes or threads read and write data items so that
the final result depends on the order of execution of instructions in the multiple processes.
Let us consider two simple examples.
Suppose that two processes, P1 and P2, share the global variable a. At some point in its
execution, P1 updates a to the value 1, and at some point in its execution, P2 updates a to the
value 2. Thus, the two tasks are in a race to write variable a. In this example, the “loser” of the
race (the process that updates last) determines the final value of a.
For second example, consider two processes, P3 and P4, that share global variables b and c,
with initial values b = 1 and c = 2. At some point in its execution, P3 executes the assignment b =
b + c, and at some point in its execution, P4 executes the assignment c = b + c. Note that the
two processes update different variables. However, the final values of the two variables depend
on the order in which the two processes execute these two assignments. If P3 executes its
assignment statement first, then the final values are b = 3 and c = 5. If P4 executes its
assignment statement first, then the final values are b = 4 and c =