1 / 14

CGS 3763 Operating Systems Concepts Spring 2013

This lecture covers topics such as Pthreads, Java threads, and CPU scheduling in operating systems. It also discusses thread management, mutexes, condition variables, and synchronization. Additionally, it explores the metrics and objectives of scheduling policies.

leotac
Download Presentation

CGS 3763 Operating Systems Concepts Spring 2013

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. CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11:30 - 12:30 AM

  2. Last time: Threads Today: Pthreads Java threads CPU scheduling Next time CPU Scheduling Reading assignments Chapters 4 and 5 of the textbook Lecture 19 – Wednesday, February 20, 2013 Lecture 19

  3. Pthreads POSIX (Portable Operating System Interface) - a family of standards specified by the IEEE for maintaining compatibility between operating systems. Pthreads – POSIX standard defining an API for thread creation and synchronization. A tutorial on Pthreads at https://computing.llnl.gov/tutorials/pthreads/#Pthread Lecture 19

  4. Pthreads • Threads use and exist within these process resources, yet are able to be scheduled by the operating system and run as independent entities largely because they duplicate only the bare essential resources that enable them to exist as executable code. • This independent flow of control is accomplished because a thread maintains its own: • Stack pointer • Registers • Scheduling properties (such as policy or priority) • Set of pending and blocked signals • Thread specific data. Lecture 19

  5. Lecture 19

  6. Timing results for: (1) the fork()subroutine; (2) the pthread_create()subroutine. Timings in seconds reflect 50,000 process/thread creations. Don't expect the system and user times to add up to real time, because these are SMP systems with multiple CPUs working on the problem at the same time. Lecture 19

  7. Pthreads API Thread management: Routines that work directly on threads - creating, detaching, joining, etc. They also include functions to set/query thread attributes (joinable, scheduling etc.) Mutexes: Routines that deal with synchronization, called a "mutex", which is an abbreviation for "mutual exclusion". Mutex functions provide for creating, destroying, locking and unlocking mutexes. These are supplemented by mutex attribute functions that set or modify attributes associated with mutexes. Condition variables: Routines that address communications between threads that share a mutex. Based upon programmer specified conditions. This group includes functions to create, destroy, wait and signal based upon specified variable values. Functions to set/query condition variable attributes are also included. Synchronization: Routines that manage read/write locks and barriers. Lecture 19

  8. Java threads • Threads  a fundamental programming model in Java. • Managed by JVM (Java Virtual Machine). • The method we use in the next example is to implement Runnable interface public interface Runnable { public abstract void run(); } • When a class implements a Runnable interface it must define a run() method. The code running when the run() method is invoked runs as a separate thread. • Two methods: • Start()  start a thread • Join()  block the calling thread until a thread terminates Lecture 19

  9. Example: Java program for summation of positive integers from 1to upper. • The Summation class implements the Runnable interface. • Creation of a thread object  create an instance of a Thread class pass the constructor a Runnableobject • The actual thread creation  use the start() method to • Allocate the memory and initialize the new thread • Call the run() method to make the thread eligible to run under JVM (Java Virtual Machine) • When the summation program runs two threads are created: • The parent thread  it starts the execution in the main() method. • The child thread created by the start()method  • it begins execution in the run() method of the Summation class. • it terminates after outputting the result and exits from its run() method. Lecture 19

  10. Lecture 19

  11. CPU scheduling • CPU scheduling – the “Running” process either relinquishes the control of the CPU by itself or it is forced by the scheduler to do so. Then the scheduler selects a process from those in the ``Ready’’ queue and gives it the control of the CPU and • Non-preemptive scheduling  the ``Running’’ process decides by itself to 1. switch from ``Running’’ to ``Waiting’’ or the ``Ready’’ state. 2. Terminates execution • Preemptive scheduling  the ``Running’’ process is forced to relinquish the control of the CPU by the scheduler. • CPU burst the period of time a process is in control of the CPU. • I/O burst  the period of time a process is in a “Waiting” state. Lecture 19

  12. Metrics and objectives of scheduling policies • Two types of systems • Batch processing of jobs • Interactive, e.g., transaction processing systems • The metrics • Utilization  ratio of useful time versus total time • Throughput  number of transactions or jobs per unit of time • Turn around time  the time it takes to complete a job • Response time  the time to get a response at a request • Waiting time  the time a job or a transaction has to wait before being processed • The objectives • Maximize: CPU utilization and Throughput • Minimize: Turn around time, Response time, Waiting time • The objectives can be contradictory!! Lecture 19

  13. Histogram of the CPU burst time Lecture 19

  14. Typical alternations of CPU and I/O bursts Lecture 19

More Related