1 / 20

Operating Systems COMP 4850/CISG 5550

Operating Systems COMP 4850/CISG 5550. Threads, Part II Dr. James Money. 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. Thread Usage. Thread Usage.

glora
Télécharger la présentation

Operating Systems COMP 4850/CISG 5550

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • – Dispatcher Thread • - Worker Thread

  6. Implementing Threads • There are two basic ways to implement threads: • In User Space • In Kernel Space • Each has it’s 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 it’s 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); • bufptr=read_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

More Related