SlideShare uma empresa Scribd logo
1 de 22
Understand Process Management
• Threads




                                            1
HOME     PREVIOUS TOPIC
NEXT
PREVIOUS QUESTION PAPERS
FOR OS
CPP TUTORIALS




                           2
Recap

In the last class, you have learnt

• Relationship between Processes

• Reasons for providing an environment that allows
  Process cooperation




                                              3
Objectives

On completion of this class, you would be able to
  know
• Definition of Thread

• Benefits of Multithread programming

• Multithreading Models




                                                    4
Thread Structure

• A thread is a light weight process (LWP)

• Basic unit of CPU utilization

• Shares other threads belonging to the same process its
  code section, data section and other resources
• Threads created for a particular process are known as
  sibling threads

                                                     5
Thread Structure


Thread comprises of
• Thread id

• Program counter

• Register counter

• Register set

• Stack

                                    6
Thread Structure
• Process having multiple threads of control, can perform more
  than one task at a time
• Threads operate, in many respects, in the same manner as
  processes
• Like processes threads can share CPU, but only one thread at a
  time is active
• Thread can create child threads
• Threads are not independent of one another
• This structure does not provide protection between threads as
  they can read or write over any other thread
                                                             7
Thread States

Thread states
• New

• Ready

• Blocked

• Running

• Terminated

                                8
Threads

Single threaded process
• A traditional (or heavy weight) Process that has a single thread
  of control

Multi threaded process
• A process which has several threads of control

• It can do more than one task at a time



                                                               9
Single and Multi Thread Process




                                                     Thread




  Single Thread Process       Multi Thread Process

                          Fig.1

                                                          10
Benefits of Multithreading Programming
Responsiveness
• Allows a program to continue even if a part of it is
   blocked or performing a lengthy operation
Resource sharing
• Threads share the memory and the resources of the
   process to which they belong
• Allows an application to have several different
   threads of activity within the same address space


                                                     11
Benefits of Multithreading Programming
Economy
• Threads share resources of the process to which
   they belong
• Hence it is more economical to create and
   conduct switch threads




                                                    12
Benefits of Multithreading Programming

Utilization of multiprocessor architectures
•   Benefits of multithreading can be greatly increased
    in a multiprocessor architecture where threads may
    be running in parallel on different processors
•   Multithreading increases concurrency on a multi-
    CPU machine


                                                       13
Multi Threading Model

• An operating system support multiple threads of execution in
  one process
• Support for threads may be provided at either the user level or
  by the kernel
• User threads are supported above the kernel and are managed
  without kernel support
• Kernel threads are supported and managed directly by
  operating system
• Windows XP. Solaris, True64 UNIX - support kernel threads
                                                            14
One process one thread                One process multiple thread

             Fig.1 (a)                              Fig.2 (b)




Multiple process, one thread per process   Multiple process, multiple threads per process


              Fig.3 (c)                                Fig.4 (d)

      Fig: multithreading model                                                      15
Multithreading Models

Many-to-one Model
• Maps many user-level threads to one kernel thread

• Green threads-a thread library available for Solaris users this
  model




                           Fig.2
                                                                16
Multithreading Models
One-to-One Model
• Maps each user thread to a kernel thread
• Windows 95/98/NT/2000/XP implement the one-to-one
  model
                                         User thread


                                          Kernel thread




                    Fig.3


                                                          17
Multithreading Models

Many-to-Many Model
• Multiplexes many user level threads to a smaller or equal
  number of kernel threads.

                                                User thread




                                            Kernel thread




                       Fig.4
                                                              18
Summary

In this class, you have learnt
•   A thread is a basic unit of CPU utilization
•   A thread is a light weight process
•   A thread shares with peer threads its code section
    data section and other resources
•   Extensive sharing makes CPU switching among
    peer threads and thread creation inexpensive

                                                         19
Frequently Asked Questions

1.   Write short notes on threads

2.   Explain the different multithreading models




                                                   20
Other subject materials
•   Web designing
•   Micro processors
•   C++ tutorials
•   java

home
Quiz
State whether the following statements are true or false
1. Thread is a light weight process
    a) True
    b) False
2. Threads can communicate with each other
    a) True
    b) False
3. A thread needs __________________
    Less no. of resources

4. A single process _____________________
   Supports multiple threads
                                                           22

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Ch04 threads
Ch04 threadsCh04 threads
Ch04 threads
 
Thread management
Thread management Thread management
Thread management
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Thread
ThreadThread
Thread
 
Treads
TreadsTreads
Treads
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
OS_Ch5
OS_Ch5OS_Ch5
OS_Ch5
 
Thread
ThreadThread
Thread
 
Networking threads
Networking threadsNetworking threads
Networking threads
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)
 
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
 
Threads
ThreadsThreads
Threads
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
 
Thread
ThreadThread
Thread
 
Operating system 21 multithreading models
Operating system 21 multithreading modelsOperating system 21 multithreading models
Operating system 21 multithreading models
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Mulitthread
MulitthreadMulitthread
Mulitthread
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 

Semelhante a 15 threads

Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxAmanuelmergia
 
Lecture 3- Threads.pdf
Lecture 3- Threads.pdfLecture 3- Threads.pdf
Lecture 3- Threads.pdfAmanuelmergia
 
Multithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdfMultithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdfHarika Pudugosula
 
Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3AbdullahMunir32
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threadsVaibhav Khanna
 
Thread (Operating System)
Thread  (Operating System)Thread  (Operating System)
Thread (Operating System)kiran Patel
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"Ra'Fat Al-Msie'deen
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfHarika Pudugosula
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationShivam Mitra
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptxbleh23
 
Multithreading
MultithreadingMultithreading
MultithreadingA B Shinde
 
threads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxthreads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxpiyushlohia1857
 
VTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingVTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingSachin Gowda
 

Semelhante a 15 threads (20)

W-9.pptx
W-9.pptxW-9.pptx
W-9.pptx
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
 
Lecture 3- Threads.pdf
Lecture 3- Threads.pdfLecture 3- Threads.pdf
Lecture 3- Threads.pdf
 
Multithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdfMultithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdf
 
Thread
ThreadThread
Thread
 
Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
 
Threads.ppt
Threads.pptThreads.ppt
Threads.ppt
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threads
 
Thread (Operating System)
Thread  (Operating System)Thread  (Operating System)
Thread (Operating System)
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
Concept of thread
Concept of threadConcept of thread
Concept of thread
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Multithreading
MultithreadingMultithreading
Multithreading
 
threads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxthreads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptx
 
VTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingVTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computing
 
Section04 threads
Section04 threadsSection04 threads
Section04 threads
 

Mais de myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

15 threads

  • 2. HOME PREVIOUS TOPIC NEXT PREVIOUS QUESTION PAPERS FOR OS CPP TUTORIALS 2
  • 3. Recap In the last class, you have learnt • Relationship between Processes • Reasons for providing an environment that allows Process cooperation 3
  • 4. Objectives On completion of this class, you would be able to know • Definition of Thread • Benefits of Multithread programming • Multithreading Models 4
  • 5. Thread Structure • A thread is a light weight process (LWP) • Basic unit of CPU utilization • Shares other threads belonging to the same process its code section, data section and other resources • Threads created for a particular process are known as sibling threads 5
  • 6. Thread Structure Thread comprises of • Thread id • Program counter • Register counter • Register set • Stack 6
  • 7. Thread Structure • Process having multiple threads of control, can perform more than one task at a time • Threads operate, in many respects, in the same manner as processes • Like processes threads can share CPU, but only one thread at a time is active • Thread can create child threads • Threads are not independent of one another • This structure does not provide protection between threads as they can read or write over any other thread 7
  • 8. Thread States Thread states • New • Ready • Blocked • Running • Terminated 8
  • 9. Threads Single threaded process • A traditional (or heavy weight) Process that has a single thread of control Multi threaded process • A process which has several threads of control • It can do more than one task at a time 9
  • 10. Single and Multi Thread Process Thread Single Thread Process Multi Thread Process Fig.1 10
  • 11. Benefits of Multithreading Programming Responsiveness • Allows a program to continue even if a part of it is blocked or performing a lengthy operation Resource sharing • Threads share the memory and the resources of the process to which they belong • Allows an application to have several different threads of activity within the same address space 11
  • 12. Benefits of Multithreading Programming Economy • Threads share resources of the process to which they belong • Hence it is more economical to create and conduct switch threads 12
  • 13. Benefits of Multithreading Programming Utilization of multiprocessor architectures • Benefits of multithreading can be greatly increased in a multiprocessor architecture where threads may be running in parallel on different processors • Multithreading increases concurrency on a multi- CPU machine 13
  • 14. Multi Threading Model • An operating system support multiple threads of execution in one process • Support for threads may be provided at either the user level or by the kernel • User threads are supported above the kernel and are managed without kernel support • Kernel threads are supported and managed directly by operating system • Windows XP. Solaris, True64 UNIX - support kernel threads 14
  • 15. One process one thread One process multiple thread Fig.1 (a) Fig.2 (b) Multiple process, one thread per process Multiple process, multiple threads per process Fig.3 (c) Fig.4 (d) Fig: multithreading model 15
  • 16. Multithreading Models Many-to-one Model • Maps many user-level threads to one kernel thread • Green threads-a thread library available for Solaris users this model Fig.2 16
  • 17. Multithreading Models One-to-One Model • Maps each user thread to a kernel thread • Windows 95/98/NT/2000/XP implement the one-to-one model User thread Kernel thread Fig.3 17
  • 18. Multithreading Models Many-to-Many Model • Multiplexes many user level threads to a smaller or equal number of kernel threads. User thread Kernel thread Fig.4 18
  • 19. Summary In this class, you have learnt • A thread is a basic unit of CPU utilization • A thread is a light weight process • A thread shares with peer threads its code section data section and other resources • Extensive sharing makes CPU switching among peer threads and thread creation inexpensive 19
  • 20. Frequently Asked Questions 1. Write short notes on threads 2. Explain the different multithreading models 20
  • 21. Other subject materials • Web designing • Micro processors • C++ tutorials • java home
  • 22. Quiz State whether the following statements are true or false 1. Thread is a light weight process a) True b) False 2. Threads can communicate with each other a) True b) False 3. A thread needs __________________ Less no. of resources 4. A single process _____________________ Supports multiple threads 22