Threads Chapter 25. A PC actually does one task at a time but threads are activities that seem to all run at once Time slicing very tiny amounts of time.

Slides:



Advertisements
Similar presentations
Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Advertisements

Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Chapter 6: Process Synchronization
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
INSE - Lectures 19 & 20 SE for Real-Time & SE for Concurrency  Really these are two topics – but rather tangled together.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
Review: Process Communication Sequential Communication –Result of P1 becomes at termination the input to P2 –Tools: Redirect (>,>>) and Pipe (|) Concurrent.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
22-Jun-15 Threads and Multithreading. 2 Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three.
Chapter 7 – Deadlock and Indefinite Postponement
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
Definitions Process – An executing program
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Java Threads CS Introduction to Operating Systems.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Today’s Agenda  Quick Review  Finish Java Threads  The CS Problem Advanced Topics in Software Engineering 1.
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Concurrent Programming. Concurrency  Concurrency means for a program to have multiple paths of execution running at (almost) the same time. Examples:
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
C20: Threads see also: ThreadedBallWorld, DropTest, Tetris source examples Not covered: advanced stuff like notify/notifyAll.
Threads II IS Outline  Quiz  Thread review  Stopping a thread  java.util.Timer  Swing threads javax.swing.Timer  ProgressMonitor.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
SurfaceView.
Review for Quiz-2 Applied Operating System Concepts Chap.s 1,2,6,7 - ECE3055b, Spring 2005.
1 Dr.A.Srinivas PES Institute of Technology Bangalore, India
1 Mouse Events See Figure See Example in Figure 11.28,
2 Processor(s)Main MemoryDevices Process, Thread & Resource Manager Memory Manager Device Manager File Manager.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Lecture 6 Page 1 CS 111 Summer 2013 Concurrency Solutions and Deadlock CS 111 Operating Systems Peter Reiher.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Outlines  Introduction  Kernel Structure  Porting.
CS203 Programming with Data Structures Introduction to Threads and Synchronization California State University, Los Angeles.
Multithreading / Concurrency
Process Management Process Concept Why only the global variables?
Applied Operating System Concepts -
Multithreaded Programming in Java
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
Threads II IS
Process Models, Creation and Termination
CS 143A Quiz 1 Solution.
Multithreading.
Midterm review: closed book multiple choice chapters 1 to 9
Multithreading.
Lecture 2 Part 2 Process Synchronization
Threaded Programming in Python
CSCI1600: Embedded and Real Time Software
Java Thread.
Scheduling.
Implementing Processes, Threads, and Resources
CSCI1600: Embedded and Real Time Software
Chapter 3: Processes Process Concept Process Scheduling
CSE 542: Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Threads Chapter 25

A PC actually does one task at a time but threads are activities that seem to all run at once Time slicing very tiny amounts of time are used for each activity (thread) then the next one gets a share of the PC’s CPU time. The threads run concurrently

Multitasking Things seem to all run at once Share a task Each thread doing one part of a whole task Independent threads: Program: “Bouncer” with old class “Ball” Uses a thread on example “Bounce2” Two threads running concurrently Dying and Killing: “Bounce3” example stop it with [button] at out command

The State of a thread(s) new (newly created) running (executing instructions) runnable (currently another thread is running but ours is ready to go) blocked (may be sleeping) dead (exited normally)

Scheduling thread priorities and yield(ing) … yield( ); allows another thread to run (our thread is not a hog of resources) The PC’s schedule actually decides what runs and how CPU time is shared (preemptable vs. nonpreemptiable) Mutual exclusion and Synchronization Only one thread allowed into a method that is “synchronized” may cause a bit of a bottleneck so keep “synchronized methods small

Program “TwoCounters” vs. “SharedNumber” Public void synchronized increment ( ) { Thread interaction – want and notify both threads want same resources (CRT) at same time Program “Poets” example of both accessing CRT writing lines mixed… A solution “Mowing” requires a request to use screen See program “ScreenController” – each gets five sconds “Clock” digital screen used, displays hours, minutes wakes after 60 second ticks

See program “Minute” and “TickTock” Class “Café” - “You want fries with that”? Buttons for placing order and timing cooking – each part of the total task “food cooked and to customer” Class “Queue” Possible problems:  Interruptions (happen in real world too)  Deadlock See “philosophers” I heard it with 5 golden forks – same problem – they need two forks to eat and have to cooperate (five forks and 5 philosophers) Mean philosophers could starve the 5 th out if they teamed up

Deadlock: “two threads waiting for something that the other thread is holding” Common causes: Ignore each other (bounce balls) Share data (..counting threads) Collaborate (café) Compete for resources (poets)