Your IP : 216.73.216.40


Current Path : /var/www/html/bibhas.ghoshal/lecture_slides/lect4/
Upload File :
Current File : /var/www/html/bibhas.ghoshal/lecture_slides/lect4/lect4.tex~

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

% This file is a template using the "beamer" package to create slides for a talk or presentation
% - Talk at a conference/colloquium.
% - Talk length is about 20min.
% - Style is ornate.

% MODIFIED by Jonathan Kew, 2008-07-06
% The header comments and encoding in this file were modified for inclusion with TeXworks.
% The content is otherwise unchanged from the original distributed with the beamer package.

\documentclass{beamer}


% Copyright 2004 by Till Tantau <tantau@users.sourceforge.net>.
%
% In principle, this file can be redistributed and/or modified under
% the terms of the GNU Public License, version 2.
%
% However, this file is supposed to be a template to be modified
% for your own needs. For this reason, if you use this file as a
% template and not specifically distribute it as part of a another
% package/program, I grant the extra permission to freely copy and
% modify this file as you see fit and even to delete this copyright
% notice. 


% \mode<presentation>
% {
%   \usetheme{Warsaw}
%   % or ...
% 
%   \setbeamercovered{transparent}
%   % or whatever (possibly just delete it)
% }
\usetheme{CambridgeUS}
\usecolortheme{beaver}

\usepackage[english]{babel}
% or whatever

\usepackage[utf8]{inputenc}
% or whatever

\usepackage{times}
%\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
\usepackage{color}
\beamertemplateshadingbackground{blue}{yellow}
%\usepackage{}
\title[IOSY 332C \& IOPS 332C: OS] % (optional, use only with long paper titles)
{ Lecture 4 - Threads}

%\subtitle
%{Include Only If Paper Has a Subtitle}

\author [Bibhas Ghoshal]% (optional, use only with lots of authors)
{ Instructor : Bibhas Ghoshal (\textcolor{black}{bibhas.ghoshal@iiita.ac.in})} 



% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
%   affiliation.

%\institute % (optional, but mostly needed)
%{
  %\inst{1}%
 % Department of Computer Science and Engineering\\
 % Indian Institute of Technology, Kharagpur}

%  \and
 % \inst{2}%
  %Department of Theoretical Philosophy\\
  %University of Elsewhere}
% - Use the \inst command only if there are several affiliations.
% - Keep it simple, no one is interested in your street address.

\date% (optional, should be abbreviation of conference name)
{Autumn Semester, 2015}
% - Either use conference name or its abbreviation.
% - Not really informative to the audience, more for people (including
%   yourself) who are reading the slides online

%\subject{Theoretical Computer Science}
% This is only inserted into the PDF information catalog. Can be left
% out. 



% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:

\pgfdeclareimage[height=0.75cm]{university-logo}{IIIT_logo.jpg}
 \logo{\pgfuseimage{university-logo}}



% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
% \AtBeginSubsection[]
% {
%   \begin{frame}<beamer>{Outline}
%     \tableofcontents[currentsection,currentsubsection]
%   \end{frame}
% }


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

%\beamerdefaultoverlayspecification{<+->}


\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}{Lecture Outline}
  \begin{itemize}
   \item Thread Concept
   \item Thread Usage
   \item Multi-threaded Process
   \item Thread Types
   \item Threading Issues
   \item Signal Handling
   \item Windows/Linux Threads
 \end{itemize}
        
        
\textcolor{red}{References and Illustrations have been used from:}
 \begin{itemize}
  \item lecture slides of the book - Operating System Concepts by Silberschatz, Galvin and Gagne, 2005 
  \item Modern Operating System by Andrew S. Tanenbaum
  \item lecture slides of CSE 30341: Operating Systems (Instructor : Surendar Chandra), 
 \end{itemize}

  
\end{frame}



 \begin{frame}{Thread Concept}


\textbf{Use of concurrency within an application incurs high process switching overhead}\\
Process switching overhead has two components:
 \begin{itemize}
  \item Execution related overhead : While switching between process, the CPU state of the running process has to be saved and state of the new process has to be loaded (unavoidable)
   \item Resource related overhead : Process environment contains information related to resources allocated to a process and its interaction with other processes. It leads to large size of  process state information, which adds to process swtching information. (avoidable)
     \end{itemize}
\end{frame}
\begin{frame}{Thread Concept}
 Switching overhead can be reduced by eliminating resource related overhead in some situations.\\
 Example: Occurence of event may result in switching of execution of process P1 to execution of P2. If both P1 and P2 belong to the same application, they share the same data, code and resources; their state information differs only in values contained in CPU, registers and stack (much of it is redundant). This feature is exploited in notion of \textcolor{green}{Thread}.\\
 
 \end{frame}
 
 \begin{frame}{Thread Usage : Need for Threads}
 
 \begin{itemize}
  \item Simpler programming model
     \begin{itemize}
      \item Decompose applications into multiple sequential threads that run in quasi-parallely
      \item Ability for parallel entities to share an address space and all of its data among themselves
     \end{itemize}
   \item Since \textbf{lightweight}, threads are easier to create and destroy
   \item Threads speed up application involving substantial computing and I/O by overlapping operations

 \end{itemize}

  
 \end{frame}

 \begin{frame}{Thread Usage Example}
  $\underline{Example 1:}$\\
  User uses word processor for writing a document. Deletes a line from page 1 and then wants to change a phrase in line 1 of page 600. The word processor has to re-format the book upto line 600 beacuse it doesn't know what will be line 1 until it has processed all other pages. Threads help here.  If the word-processor is written as a three threaded program :
  \begin{itemize}
   \item Interactive thread - listens to the keyboard and mouse to accept commands
   \item computing madly in background
   \item saving document automatically
  \end{itemize}

  
  
 \end{frame}

 
 
 
 
 \begin{frame}{Thread Concept}
 
 
 \textcolor{green}{Thread} : A program execution that uses resources of the process\\
 \begin{itemize}
  \item A thread has its own stack and CPU state
  \item Thread of same process share code,data and resources with one another
  \item Kernel allocates stack and Thread Control Block to each thread
  \item OS saves only CPU state and stack while switching between threads
 \end{itemize}

 
\end{frame}


\begin{frame}{Thread States}
 Threads and Process are analogous barring no allocation of resources to threads. Thus, process and thread states are anologous\\
 \begin{itemize}
  \item When a thread is created, it is put in \emph{ready} state as its parent process already has the resources allocated to it.
  \item It enters \emph{running} state when scheduled
  \item It does not enter \emph{blocked} state since it does not request resource; however it can enter bloked state due to process synchronization requirement
 \end{itemize}

 

 
\end{frame}





\begin{frame}{Single and Multithreaded Processes}
 \begin{figure}
  \centering
  \includegraphics[width=0.55\textwidth]{thread.pdf}
  %\caption{Process created during execution of a.out}
 \end{figure}

\end{frame}

\begin{frame}{Advantages of threads}
 \begin{itemize}
  \item Low overhead - contains only state of computation
 \item Responsiveness - Interactive applications can be performing two tasks at the same time (rendering, spell checking)

 \item Resource Sharing - Sharing resources between threads is easy (too easy?)

 \item Economy - Resource allocation between threads is fast (no protection issues)
 \item Speed-up - concurrency is realized by creating many threads within a process
  \item Efficient communication - threads of a processs communicate through shared data space, avoiding system calls for communication

\item Utilization of MP Architectures - seamlessly assign multiple threads to multiple processors (if available). Future appears to be multi-core anyway
 
  
 \end{itemize}

\end{frame}


\begin{frame}{Thread types}
\begin{itemize}
 \item User threads: thread management done by user-level threads library. Kernel does not know about these threads
  \begin{itemize}
   \item Three primary thread libraries:
      \begin{itemize}
       \item POSIX Pthreads
      \item Win32 threads
      \item Java threads
      \end{itemize}

  \end{itemize}
\item Kernel threads: Supported by the Kernel and so more overhead than user threads
   \begin{itemize}
    \item Examples: Windows XP/2000, Solaris, Linux, Mac OS X
   \end{itemize}
\item 
User threads map into kernel threads
\end{itemize}

\end{frame}

%  \begin{frame}{Thread types}
%  \begin{itemize}
%   \item User threads: thread management done by user-level threads library. Kernel does not know about these threads
% \item Three primary thread libraries:
%     \begin{itemize}
%   \item POSIX Pthreads
%    \item Win32 threads
%     \item Java threads
%       \end{itemize}
% \item Kernel threads: Supported by the Kernel and so more overhead than user threads
% 	  \begin{itemize}
% 		  \item Examples: Windows XP/2000, Solaris, Linux, Mac OS X
% 	    \end{itemize}
% \item User threads map into kernel threads
%  \end{itemize}
% 
%  \end{frame}
%  
%  
%  \begin{frame}{Multi-threading models}
%  \begin{itemize}
%   \item Many-to-One: Many user-level threads mapped to single kernel thread
% 
% 	    \begin{itemize}
% 		\item If a thread blocks inside kernel, all the other threads cannot run
% 		\item Examples: Solaris Green Threads, GNU Pthreads
% 
% 	     \end{itemize}
% \item One-to-One: Each user-level thread maps to kernel thread
% \item Many-to-Many: Allows many user level threads to
% 	    \begin{itemize}
% 		\item Allows the  operating system to create a sufficient number of kernel threads
% 	      \end{itemize}
% 
%  \end{itemize}
% 
%  
% 
% 
% \end{frame}
% 


\end{document}