Adobe Scan Sep 12, 2024
Adobe Scan Sep 12, 2024
The human body performs a great variety of operations in concurrentlv., for example
seeing. touching, smelling, tasting and hearing can occur concurrently. An automobile can
he accelerating , turning, air conditioning, and playing music connectively. The programmer
specifies that application contain "Threads of execution". Eachthread designating portion of
programthat may be execute concurrently with other threads. This capability is called
multithreading.
Life eycle of thread:Athread is said to be in one of following several thread states.
Born State: A thread that has just created.
Ready state: The thread is waiting for processor (CPU)
Running: The system assigns the processor to the thread( i.e the thread being
executing)
Blocked state: The thread is waiting for an event to occur (or) waiting for an /O
4
device.
Sleep: A sleeping thread becomes ready after the designated sleep time expires.
Dead: The execution of the thread finished.
thread.
Considering the following figure 3.9 to understand the life cycle of a
Born
Ready
Ruqing
Blocked
Waiting (Sleeping) Dead
Examples of threads
the programine
word processor: A programmer wish to type the text in word processor. Then
thread) the text is automaticany
Ppen aile in word processor , and typing the text( It is one mistakes,it
ormatting ( It is another thread),The text is automatically specifies the spelling
thread. 1yps
S another thread, and the file is automatically saved in the disk .it is another are threads. For
n afile is the saving these
process. Buttyping , Formatting. Spell checking
txample consider the figure 3.10
tthreads
he areWn
table,
tircad two Bserthreads.Tecord
atesynchronization
Tese Thread Thread
of functionality
Thread
thread threads
lel er tnreads
with in
10.Processes 9.
It 8. 7. (6. 5. A. 3. 3it I. Process
threadys
level activities.
Parallel execute.
Process other.
communicate each difficuit.
in requires
between System
Implementing
prOcesses.
betweentwExecution
o It the proccss.
It memory
process
e states: tahes takes takes
execution
table file, a
cQnsists threads of and
is callsprocesses more more more
nanagedmanaged main
kernel it Already are
moreloosely is areacantProcess
will are
a not time very tme
the loaded ways the and time (addressshare
process
effect suitableresources
information
level
discussed coupled. requiredcommunication
is slow.
to
D in
by andto terminate. to to
the
a switch complete
withshare create
run entirely
use inplement
threads bit space) same
for to to more
time space, another a
the in
of in memory section
system.
program each user threads: threads,
10. 9. 8. 7. 6. 5. 4. 3. 2.
processspace, 3.5 1.
When in and SuitableRequired
also Threads Systemthreads are threads.
Communication wo It
tExecution Less It
counter, so takes takes Threads
the user files. collected very Thread
needs need time
thread
a kernel space for fewer are calls shareeasy less less can Process
stack toOne is to
i<s try parallel tightly are the to time very terminate. time share
own thread lightweight
process. Descrition
is knows synchronizing resources, not between
implemen,
pointer, memory. to
fast. to
moved
private
kernel.
the in coupled. Switch create memory
is activities. required.
nothing trying
registers,
lo two
a
and
so betwèen and
ready thread
table,the
to it Because
threads
thread control3.13
about the is files.
modity
state state dCthViies
the
elc.
or one
3.12 Operating Systems
Threads
3.7 Processes and section 3.5. Now we are going to be discussed
about threads in
Already we discussed
multithreing.
S.7.y Multithreading smaller tasks, cach task is called a 'thread'. Numbe.
processisdivided into number of time is called 'multithreading .
Supporting
process execute at a Based onthe
Hhreads with in a
multithreading isthe additional capability of an operating
system. functionalit,
threads are divided into 4 categories these are.
Threads
Multiple Multiple
Process,one ProceSs,
thread per Multiple
process Threads
Figure 3.12
Oneprocess one thread: It is a traditional approach, in which the process maintains
one thread, so it is called single threaded approach. For example MS-DO8
operating system supports this type of approach.
2. One process, multiple threads: Inwhich a process Civided into number of threads
best example for this one is 'JAVA runtime environment'.
3. Multiple process, one thread per process: Anoperating system support multip#
user processes but only support one thread per process. Best example for this typ
is UNIX.
Î Multiple processes, multiple threads per process: In which each process divided
into nunber of threads, example for this type is windows 2000, Solaris LINUX.
Bhefits of a Thread
/A thread takes less time to terminate, than the process.
It takes less time to switch between two threads within the same
process.
It takes less ime lo creale a new thread within the
process.
Efficient communication between threads.
3.14 Onedting Syste ms
restart it is stored in the thread table. Consider the
to
The information needed
blocked suate.
below igure.
Thread Process Thread
Process
User
space
Kernal
space
Adyantagés
U_¿r level threads allow each process to have its own scheduling algorithm.
not switch to the kernel
2. The entire process loaded in user space, so the process does
mode switches.
mode to do thread management.This saves the overhead of two
3. Useplevel threads can run on any operating system.
Disadvantages
1./Whh user level thread executes a system call, not only the particular thread blocked.
a> of the threads with in the process are blocked.
2. In user level threads, only a single thread with in a process can execute at a time. So
multi pfocessing is can't implemented.
Kernelevel Threads
In Kgfnel level threads the kernel does total work of thread movement. There is no thread
table in each process. The kernel has a thread table that keeps track of all the threads i
system. When a thread wants tocreate a new thread or destroy any existing thread, it makes
a kernel call, which takes the action. .
The kernel's thread table holds each thread registers, state and other information. The
information is the same as with user level threads, but it is now in the kernel instead of the
user space. Consider the below figure for better understanding.
Process Descrition and control ¢3.15
User
space
Kernal Kernal
space
Thread table
Process table
Ligure 3.J4
Advantages
Lthe kernel can simultaneously schedule a multiple threads from the same process
on multiple processors. It means it supports multi processing where as user level
threads can't support this.
2 A thread in a process is blocked; the kernel can schedule another thread of the same
process.
Disadvantages
T. More cost for creating and destroying threads in the kernel.
2. The transfer of control from one thread to another with in the same
process requires
a mode switch to the kernel.
Combined approaches
1f we combine the both approaches (user level, kernel level) then we get the
advantages of
both. Some operating systems provide this type of facility. In combined system thread creation
Is done completely in user space. Best example for this approach is 'Solaris"