Processes & Threads

buninnateΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 4 χρόνια και 5 μήνες)

120 εμφανίσεις

Processes & Threads

Resource ownership

Process or Task


Thread or lightweight process

One process,

one thread (MS

One process,

multiple threads (Java Runtime)

Multiple processes,

multiple threads (W2K, Solaris, Linux)

Multiple processes,

one thread per process (Unix)

Processes & Threads (continue)

In a multithreaded environment, the followings are
associated with a process:

Address space to hold the process image

Protected access to processors, other processes (IPC), files, and I/O
resources (devices & channels)

Within a process, there may be one or more threads, each
with the following:

A thread execution state (Running, Ready, etc)

A saved context when not running

a separate program counter

An execution stack

Some static storage for local variables for this thread

Access to memory and resources of its process, shared with all
other threads in that process (global variables)

Single Threaded and Multithreaded Process Models

Key Benefits of Threads

It takes far less time to create a new thread in an existing
process than to create a brand
new process. (10X)

It takes less time to terminate a thread than a process.

It takes less time to switch between two threads within the
same process.

Threads enhance efficiency in communication between
different executing programs

since threads within the
same process share memory and files, they can
communicate with each other without invoking the kernel.

Key Benefits of Threads (continue)

Key Benefits of Threads (continue.)

Thread Functionality

Thread States

Running, Ready, and Blocked

Suspend is at process

Four Basic Thread Operations for a change in Thread State

: threads can be spawned from a process or a thread within the same
process which provide an instruction pointer and its arguments. The new thread
will have its own register context and stack space and be out in the Ready Queue.

: When a thread needs to wait for an event, it will block (saving its user
registers, program counter, and stack pointer). The processor may now turn to
execute another ready thread.

: When the waited event occurs, the waiting thread is moved to the Ready

: When the thread completes, its register context and stacks are deallocated.

Thread Synchronization

To be covered in Chapter 5 & 6.

Level and Kernel
Level Threads

Level Threads

Thread management is done by the application and the kernel is
not aware of the existence of threads


Thread switching does not require user/kernel mode

Thread scheduling can be application specific.

ULTs can run on any O.S through a thread library.


When a ULT executes a system call, not only the thread is
blocked, but all of the threads within the process are blocked.

Multithreaded application cannot take advantage of
multiprocessing since kernel assign one process to only one
processor at a time.

Level Threads

Thread management is done by the kernel. No threaded
management code in the application

W2K, Linux.


The kernel can scheduling multiple threads from the same
process on multiple processors.

If one thread is blocked, the kernel can schedule another
thread on the same process.

Kernel routines themselves can be multithreaded.


Thread switching within the same process requires kernel
mode switching

User and Kernel
Level Threads Performance


Null fork
: the time to create, schedule, execute, and complete a process/thread that
invokes the null procedure.

: the time for a process/thread to signal a waiting process/thread and
then wait on a condition.

Procedure call: 7us

Kernel Trap:17us

Thread Operation Latencies





Null fork




Signal Wait





While there is a significant speedup by using KLT multithreading compared to single
processes, there is an additional significant speedup by using ULTs.

However, whether or not the additional speedup is realized depends on the nature of the
applications involved.

If most of the thread switches require kernel mode access, then ULT may not perform much better
than KLT.