Professional Documents
Culture Documents
Threads
PRESENTED BY
ABSTRACT
The CPU switches rapidly back and forth among the threads giving illusion
that the threads are running in parallel. Like a traditional process i.e., process
with one thread, a thread can be in any of several states (Running, Blocked,
Ready or Terminated).
Each thread has its own stack. Since thread will generally call different
procedures and thus a different execution history. This is why thread needs its
own stack.
Each thread belongs to exactly one process and no thread can exist outside a process. Each thread
represents a separate flow of control. Threads have been successfully used in implementing network
servers and web server. They also provide a suitable foundation for parallel execution of applications
on shared memory multiprocessors.
Process
Thread
Why Threads?
Following are some reasons why we use threads in designing operating systems.
A process with multiple threads make a great server for example printer server.
Because threads can share common data, they do not need to use interprocess
communication.
Threads are cheap in the sense that they only need a stack and storage for registers therefore,
threads are cheap to create.
Threads use very little resources of an operating system in which they are working. That is,
threads do not need new address space, global data, program code or operating system
resources.
Context switching are fast when working with threads. The reason is that we only have to save
and/or restore PC, SP and registers.
But this cheapness does not come free - the biggest drawback is that there is no protection
between threads.
Advantages of Thread
Efficient communication.
Types of Thread
ADVANTAGES
DISADVANTAGES
ADVANTAGES
Kernel can simultaneously schedule multiple threads from the same process on multiple
processes.
If one thread in a process is blocked, the Kernel can schedule another thread of the
same process.
DISADVANTAGES
Kernel threads are generally slower to create and manage than the user threads.
Transfer of control from one thread to another within same process requires a mode
switch to the Kernel.
Multithreading Models
Some operating system provide a combined user level thread and
Kernel level thread facility.
Solaris is a good example of this combined approach.
In a combined system, multiple threads within the same application
can run in parallel on multiple processors .
Multithreading models are three types
Many to many relationship.
Many to one relationship.
In this model, many user level threads multiplexes to the Kernel thread of
smaller or equal numbers. The number of Kernel threads may be specific to
either a particular application or a particular machine.
Many to one model maps many user level threads to one Kernel level
thread. Thread management is done in user space. Only one thread can
access the Kernel at a time,so multiple threads are unable to run in parallel
on multiprocessors.
There is one to one relationship of user level thread to the kernel level
thread. It support multiple thread to execute in parallel on
microprocessors.
User level thread is generic and can run Kernel level thread is specific to the operating
on any operating system.
system.
A proxy server satisfying the requests for a number of computers on a LAN would be benefited by a multithreaded process. In general, any program that has to do more than one task at a time could benefit from
multitasking. For example, a program that reads input, process it, and outputs could have three threads, one
for each task.
Any sequential process that cannot be divided into parallel task will not benefit from thread, as they would
block until the previous one completes. For example, a program that displays the time of the day would not
benefit from multiple threads.
THANK YOU!!!