7th Lecture OS
7th Lecture OS
7th Lecture OS
CS(407)
LECTURE 7
THREADS
INSTRUCTOR
SIBGHA ZIA
DEPARTMENT OF COMPUTER SCIENCE
UAF SUB CAMPUS BUREWALA
THREADS
A thread is a path of execution within a process. A process can
contain multiple threads.
It is a sequences of instruction within a process. A thread behave like
a process with in a process.
THREAD
A thread is a basic unit of CPU utilization, consisting of a program
counter, a stack, and a set of registers, ( and a thread ID. )It is also called
a light weight entity.
This is particularly true when one of the tasks may block, and it is
desired to allow the other tasks to proceed without blocking.
Register set
Stack space
NEED OF THREAD
It takes far less time to create a new thread in an existing process
than to create a new process.
Threads can share the common data, they do not need to use Inter-
Process communication.
Context switching is faster when working with threads.
kernel threads
User threads are supported above the kernel, without kernel support.
These are the threads that application programmers would put into
their programs.
Kernel threads are supported within the kernel of the OS itself. All
modern OS support kernel level threads, allowing the kernel to
perform multiple simultaneous tasks and/or to service multiple kernel
system calls simultaneously
USER-LEVEL THREAD
The operating system does not recognize the user-level thread. User
threads can be easily implemented and it is implemented by the user.
If a user performs a user-level thread blocking operation, the whole
process is blocked. The kernel level thread does not know nothing
about the user level thread.
examples: Java
Disadvantages:
Threads libraries:
A thread library provides API to create and manage threads. There are
two ways to implement the thread library.
1st Approach is to provide a library exist in user space with no kernel
support.
2nd Approach is to implement kernel level library supported by operating
system.