1 / 10

EECE.4810/EECE.5730 Operating Systems

EECE.4810/EECE.5730 Operating Systems. Instructor: Dr. Michael Geiger Spring 2019 Lecture 9: Threads. Lecture outline. Announcements/reminders Program 1 due today Write one program that does everything

caia
Télécharger la présentation

EECE.4810/EECE.5730 Operating Systems

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. EECE.4810/EECE.5730Operating Systems Instructor: Dr. Michael Geiger Spring 2019 Lecture 9: Threads

  2. Lecture outline • Announcements/reminders • Program 1 due today • Write one program that does everything • Objective list is an outline that could be used to guide development, but feel free to skip steps • If wait() returns -1, called from process without child! • Please respond to the exam scheduling poll • Today’s lecture • Review: multithreading basics • Continue threading discussion • Pthread example programs Operating Systems: Lecture 8

  3. Review: Threads • Thread: active sequence of instructions • Basic unit of CPU utilization • Thread creation is lightweight • Multiple threads in same process can share address space • Each thread needs own PC, register copies, stack + SP • Threads provide concurrency within application • HW support necessary for parallelism • Major issue: non-deterministic ordering • Solutions require atomic operations • Avoid race condition: solution depends on timing/ordering of earlier events Operating Systems: Lecture 6

  4. Example Thread AThread B i = 0 i = 0 while (i < 10) while (i > -10) i++ i-- print “A done” print “B done” • Which thread finishes first? • Is winner guaranteed to print first? • Is it guaranteed that one thread will win? • What’s required to guarantee one thread will win? Operating Systems: Lecture 8

  5. Multithreaded debugging • Non-deterministic ordering makes debugging difficult • “Heisenbug”: bug that occurs non-deterministically • All possible interleavings must be correct • Race condition: output/result dependent on timing or ordering of earlier events • Becomes bug when unanticipated ordering occurs • Potentially disastrous consequences • Over-radiation in Therac-25 • 2 modes of operation: direct low-power radiation, high-powered radiation + safeguards • Race condition activated high-powered beam w/o safeguards • Northeast blackout of 2003 • Race condition in control software Operating Systems: Lecture 8

  6. Synchronization • Constrain interleavings between threads • Goal: force all possible interleavings to produce correct result • Correct concurrent program should work regardless of processor speed • Try to constrain as little as possible • Some events are independent—order irrelevant • Order only matters in dependent events • Synchronization: Controlling execution and order of threads Operating Systems: Lecture 8

  7. Pthreads • POSIX thread API (Pthreads) supported on most systems • Necessary functions included in <pthread.h> • Files may need to be compiled with –pthread or –lpthread option • Library contains functions for: • Thread creation and termination • Thread joining (forced waiting  simple synch) • Synchronization (locks, condition variables, barriers) • Other thread management Operating Systems: Lecture 6

  8. Pthread examples • Three example programs • Functions covered • pthread_create(thread, attr, start_routine, arg) • pthread_exit(status) • pthread_join(thread, status) Operating Systems: Lecture 6

  9. Final notes • Next time • Detailed synchronization discussion • Reminders: • Program 1 due today • Write one program that does everything • Objective list is an outline that could be used to guide development, but feel free to skip steps • If wait() returns -1, called from process without child! Operating Systems: Lecture 8

  10. Acknowledgements • These slides are adapted from the following sources: • Silberschatz, Galvin, & Gagne, Operating Systems Concepts, 9th edition • Chen & Madhyastha, EECS 482 lecture notes, University of Michigan, Fall 2016 Operating Systems: Lecture 8

More Related