SlideShare una empresa de Scribd logo
1 de 16
THREADS
          By N.B.SHETTY
INTRODUCTION
   A thread is contained       Process and threads
    inside a process and
    different threads in the
    same process share some
    resources (most
    commonly memory),
    while different processes
    do not.
INTRODUCTION
   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. )
   On a single processor, multithreading generally
    occurs by as in multitasking, the processor
    switches between different threads.
   On a multiprocessor or multi-core system, the
    threads or tasks actually do run at the same time,
    with each processor or core running a particular
    thread or task
SINGLE AND MULTI THREAD
   Single Thread
     Has single thread of control

     It allows the process to perform only 1 task at a time.

   Multi thread
     Has many threads

     Simultaneous execution of different task
BENEFITS
   Take less time to create a new tread than a process.
   Less time to terminate a tread than a presses.
   less time to switch between two treads within the same
    process.
   Hence treads within the same process share memory and
    files, they can communicate with each other without
    invoking the kernel.
   Responsiveness.
   Resource sharing .
   Economy.
   Utilization of MP Architectures.
User Threads
   Thread management done by user-level threads
    library
       Thread creation, scheduling, are done in user level
   Fast to create and manage
   Drawback:
       If kernel is single thread, then user level thread
        performing a blocking system call will cause entire
        process to block
KERNEL THREAD
   Supported by OS
       Thread creation, scheduling, are done in user level by
        kernel
   Thread management is performed by os, thus
    kernel thread are slow.
   If thread perform blocking system call, kernel can
    schedule another thread in application for
    execution
Multithreading Models
(In a specific implementation, the user threads
must be mapped to kernel threads, using one
of the following strategies. )

Many-to-One


One-to-One


Many-to-Many
MANY-TO-ONE
   many user-level threads are
    all mapped onto a single
    kernel thread.
   Thread management is
    handled by the thread library
    in user space, which is very
    efficient.
   if a blocking system call is
    made, then the entire process
    blocks, even if the other user
    threads would otherwise be
    able to continue.
   Ex: Green threads for Solaris
    and GNU Portable
ONE-TO-ONE MODEL
   Each user-level thread maps to kernel thread
   Allow anther thread to run if block
   Run parallel
   Drawback: along with user thread kernel thread shld be
    created.
   Ex: Linux and Windows from 95 to XP
MANY-TO-MANY
   The many-to-many model
    multiplexes any number of user
    threads onto an equal or
    smaller number of kernel
    threads, combining the best
    features of the one-to-one and
    many-to-one models.
   Blocking kernel system calls do
    not block the entire process.
   Individual processes may be
    allocated variable numbers of
    kernel threads, depending on
    the number of CPUs present
    and other factors.
   Ex: RIX, HP-UX, and Tru64
    UNIX
Thread Libraries
   Thread libraries provide programmers with an API
    for creating and managing threads.
   Thread libraries may be implemented either in user
    space or in kernel space.
   There are three main thread libraries in use today:
    POSIX Pthreads .
   Win32 threads.
   Java threads .
Pthreads
   May be provided either as user-level or kernel-level.

   A POSIX standard (IEEE 1003.1c) API for thread
    creation and synchronization.

   API specifies behavior of the thread library,
    implementation is up to development of the library.

   Common in UNIX operating systems (Solaris,
    Linux, Mac OS X).
Linux Threads
   Linux refers to them as tasks rather than
    threads.
   Thread creation is done through clone()
    system call.
   clone() allows a child task to share the
    address space of the parent task (process).
Treads

Más contenido relacionado

La actualidad más candente

Multithreading models
Multithreading modelsMultithreading models
Multithreading modelsanoopkrishna2
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-GalvinSonali Chauhan
 
Concept of thread, multi thread, tcb
Concept of thread, multi thread, tcbConcept of thread, multi thread, tcb
Concept of thread, multi thread, tcbKanza batool
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingguesta40f80
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating SystemsNitish Gulati
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.pptLuis Goldster
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Multi threading models(operating systems)
Multi threading models(operating systems)Multi threading models(operating systems)
Multi threading models(operating systems)jakeer3764
 
An Introduction to threads
An Introduction to threadsAn Introduction to threads
An Introduction to threadsZahra Sadeghi
 
Multithreading
Multithreading Multithreading
Multithreading WafaQKhan
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsPeter Tröger
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programmingAnyapuPranav
 

La actualidad más candente (20)

Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 
OS_Ch5
OS_Ch5OS_Ch5
OS_Ch5
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
Threads
ThreadsThreads
Threads
 
Thread
ThreadThread
Thread
 
Thread
ThreadThread
Thread
 
Concept of thread, multi thread, tcb
Concept of thread, multi thread, tcbConcept of thread, multi thread, tcb
Concept of thread, multi thread, tcb
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
 
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Multi threading models(operating systems)
Multi threading models(operating systems)Multi threading models(operating systems)
Multi threading models(operating systems)
 
Threading
ThreadingThreading
Threading
 
An Introduction to threads
An Introduction to threadsAn Introduction to threads
An Introduction to threads
 
Multithreading
Multithreading Multithreading
Multithreading
 
Lecutur24 25
Lecutur24 25Lecutur24 25
Lecutur24 25
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 

Similar a Treads (20)

Wiki 2
Wiki 2Wiki 2
Wiki 2
 
Os
OsOs
Os
 
Threads
ThreadsThreads
Threads
 
W-9.pptx
W-9.pptxW-9.pptx
W-9.pptx
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
 
Thread
ThreadThread
Thread
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
 
Chapter04 new
Chapter04 newChapter04 new
Chapter04 new
 
Lecture 3- Threads.pdf
Lecture 3- Threads.pdfLecture 3- Threads.pdf
Lecture 3- Threads.pdf
 
4.Process.ppt
4.Process.ppt4.Process.ppt
4.Process.ppt
 
Sucet os module_2_notes
Sucet os module_2_notesSucet os module_2_notes
Sucet os module_2_notes
 
Chapter 4 - Threads
Chapter 4 - ThreadsChapter 4 - Threads
Chapter 4 - Threads
 
thread os.pptx
thread os.pptxthread os.pptx
thread os.pptx
 
CH04.pdf
CH04.pdfCH04.pdf
CH04.pdf
 
Threads ppt
Threads pptThreads ppt
Threads ppt
 
Epc 3.ppt
Epc 3.pptEpc 3.ppt
Epc 3.ppt
 
Thread
ThreadThread
Thread
 

Treads

  • 1. THREADS By N.B.SHETTY
  • 2. INTRODUCTION  A thread is contained Process and threads inside a process and different threads in the same process share some resources (most commonly memory), while different processes do not.
  • 3. INTRODUCTION  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. )  On a single processor, multithreading generally occurs by as in multitasking, the processor switches between different threads.  On a multiprocessor or multi-core system, the threads or tasks actually do run at the same time, with each processor or core running a particular thread or task
  • 5. Single Thread  Has single thread of control  It allows the process to perform only 1 task at a time.  Multi thread  Has many threads  Simultaneous execution of different task
  • 6. BENEFITS  Take less time to create a new tread than a process.  Less time to terminate a tread than a presses.  less time to switch between two treads within the same process.  Hence treads within the same process share memory and files, they can communicate with each other without invoking the kernel.  Responsiveness.  Resource sharing .  Economy.  Utilization of MP Architectures.
  • 7. User Threads  Thread management done by user-level threads library  Thread creation, scheduling, are done in user level  Fast to create and manage  Drawback:  If kernel is single thread, then user level thread performing a blocking system call will cause entire process to block
  • 8. KERNEL THREAD  Supported by OS  Thread creation, scheduling, are done in user level by kernel  Thread management is performed by os, thus kernel thread are slow.  If thread perform blocking system call, kernel can schedule another thread in application for execution
  • 9. Multithreading Models (In a specific implementation, the user threads must be mapped to kernel threads, using one of the following strategies. ) Many-to-One One-to-One Many-to-Many
  • 10. MANY-TO-ONE  many user-level threads are all mapped onto a single kernel thread.  Thread management is handled by the thread library in user space, which is very efficient.  if a blocking system call is made, then the entire process blocks, even if the other user threads would otherwise be able to continue.  Ex: Green threads for Solaris and GNU Portable
  • 11. ONE-TO-ONE MODEL  Each user-level thread maps to kernel thread  Allow anther thread to run if block  Run parallel  Drawback: along with user thread kernel thread shld be created.  Ex: Linux and Windows from 95 to XP
  • 12. MANY-TO-MANY  The many-to-many model multiplexes any number of user threads onto an equal or smaller number of kernel threads, combining the best features of the one-to-one and many-to-one models.  Blocking kernel system calls do not block the entire process.  Individual processes may be allocated variable numbers of kernel threads, depending on the number of CPUs present and other factors.  Ex: RIX, HP-UX, and Tru64 UNIX
  • 13. Thread Libraries  Thread libraries provide programmers with an API for creating and managing threads.  Thread libraries may be implemented either in user space or in kernel space.  There are three main thread libraries in use today:  POSIX Pthreads .  Win32 threads.  Java threads .
  • 14. Pthreads  May be provided either as user-level or kernel-level.  A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization.  API specifies behavior of the thread library, implementation is up to development of the library.  Common in UNIX operating systems (Solaris, Linux, Mac OS X).
  • 15. Linux Threads  Linux refers to them as tasks rather than threads.  Thread creation is done through clone() system call.  clone() allows a child task to share the address space of the parent task (process).