Software Requirements Specification Srs
Software Requirements Specification Srs
Systems
LECTURE 11-12
Threads 2
Definitions
In the previous discussion, a process was an executing program
with a single thread of control.
Most modern OS now provide features enabling a process to
contain multiple threads of control.
A thread is a basic unit of CPU utilization.
It is a light weight process.
If a process has multiple thread of control, it can perform more
than one task at a time.
Seamless execution of two or more sections of a program at the
same time. Threads allows us to do this.
Process, threads 3
ANSWER!
There is no standard threading library that is implemented on
all platforms.
Threads 10
Benefits
Responsiveness
Multithreading interactive application may allow a program to
continue running even if a part of it is blocked or is performing a
lengthy operation.
For example, a multithreaded web browser could still allow user
interaction in one thread while an image was being loaded in
another thread.
Resource sharing
By default, threads share the memory and the resources of the
process to which they belong.
The benefits of sharing code and data is that it allows an application
to have several different threads of activity within the same address
space.
Threads 12
Economy
Allocating memory and resources for process
creation is costly.
It is more economical to create and context switch
threads.
In Solaris, creating a process is about thirty times
slower than is a creating a thread, and context
switching is about five time slower.
Threads 13
States Description
Ready The thread is ready to run and waiting
for the CPU.
Running The thread is executing on the CPU.
Waiting The thread is waiting for some event to
happen.
Sleeping The thread has been told to sleep for a
time
Blocked The thread is waiting for I/O to finish
dead The thread is terminated
Thread life cycle (JAVA) 16
Born
Thread stack 17
Thread states 18
T1 T2 T3 T4 T1 T2 T3
User Space
T1 T2
Kernel Space
Thread
Execution Context
Threads
Implementation(JAVA)
31
system.err.println("starting thread");
thread1.start();
thread2.start();
thread3.start();
}//end of main
}
Threads in JAVA 32
catch(InterruptedException e)
{
e.printStackTrace();
} //end catch
system.err.println(getName() + "done sleeping");
}//end method run
}// end class PrintThread.
Output 34
Starting threads
Treads started, main ends