Operating Systems COMP 4850/CISG 5550 - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Operating Systems COMP 4850/CISG 5550

Description:

Thread Usage. Why are they used? Programs block, but might have other tasks to perform ... but the process may have multiple user space threads for one kernel thread ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 21
Provided by: nccu
Category:

less

Transcript and Presenter's Notes

Title: Operating Systems COMP 4850/CISG 5550


1
Operating SystemsCOMP 4850/CISG 5550
  • Threads, Part II
  • Dr. James Money

2
Thread Usage
  • Why are they used?
  • Programs block, but might have other tasks to
    perform
  • Easier to create/destroy than processes
  • Increase in performance
  • Multiple CPU utilization

3
Thread Usage
4
Thread Usage
5
Thread Usage
  1. Dispatcher Thread
  2. - Worker Thread

6
Implementing Threads
  • There are two basic ways to implement threads
  • In User Space
  • In Kernel Space
  • Each has its own advantages and disadvantages

7
User Space Threads
  • The OS knows nothing about threads.
  • Each process has its own user space thread table
    similar to the process table

8
User Space Threads
9
User Space Threads
  • Advantages
  • No traps to kernel mode better performance
  • Custom scheduling algorithms
  • Scales well
  • Disadvantages
  • Dealing with blocking system calls
  • Page faults block all threads
  • Requires voluntary yielding of CPU

10
Kernel Space Threads
  • Kernel maintains thread table
  • When a system call blocks, the kernel can run
    another thread automatically
  • Threads tend to get recycled not actually
    destroyed since they require a trap

11
Kernel Space Threads
12
Hybrid Implementations
  • Research has been done on implementing kernel and
    user space threads at the same time.
  • The kernel knows about its threads, but the
    process may have multiple user space threads for
    one kernel thread

13
Hybrid Implementations
14
Making Single Threaded Code Multithreaded
  • Most programs are written for one thread
  • We must convert them to multithread form to use
    them in a threaded system
  • This is not easy to perform in general.

15
Multithreaded systems
  • Possible overwriting of global variables

16
Multitheaded Systems
  • Solutions
  • Multiple global variables similar to separate
    stacks
  • Thread wide global variable library

17
Multithreaded Systems
18
Private Library
  • create_global(bufptr)
  • set_global(bufptr,buf)
  • bufptrread_global(bufptr)

19
Multithreaded Systems
  • Library procedures are not re-entrant usually!
  • Buffered message passing may get overwritten.
  • Must rewrite these functions
  • Or completely block re-use of the library
    functions when one is in use.

20
Multithreaded Systems
  • Thread management issues
  • Many times the kernel will just extend the stack
    when it overflows
  • This can cause two separate thread stacks to
    collide now
Write a Comment
User Comments (0)
About PowerShow.com