Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.

Slides:



Advertisements
Similar presentations
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Bilgisayar Mühendisliği Bölümü GYTE - Bilgisayar Mühendisliği Bölümü Multithreading the SunOS Kernel J. R. Eykholt, S. R. Kleiman, S. Barton, R. Faulkner,
COP 4600 Operating Systems Fall 2010 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:30-4:30 PM.
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Concurrency…leading up to writing a web crawler. Web crawlers.
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
Java ThreadsGraphics Programming Graphics Programming: Java Threads.
1 MATERI PENDUKUNG SINKRONISASI Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Copyright © The McGraw-Hill Companies, Inc
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
50.003: Elements of Software Construction Week 5 Basics of Threads.
Chapter 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
Windows Programming Using C# Threading. 2 Contents Threading Thread class Interlocked class Monitor class Semaphore class Thread Pools.
Solution to Dining Philosophers. Each philosopher I invokes the operations pickup() and putdown() in the following sequence: dp.pickup(i) EAT dp.putdown(i)
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
17.16 Synthesis of Thyroid Hormone (TH) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slide number: 1.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Multithreading Chapter Introduction Consider ability of human body to ___________ –Breathing, heartbeat, chew gum, walk … In many situations we.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Multithreading [Modified]
Advanced Concurrency Topics Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Multi-Threading in Java
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R E L E V E N Concurrent Programming.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
T HREADS Lecture 5 1 L. Mohammad R.Alkafagee. H EAVYWEIGHT - PROCESSES The cooperation of traditional processes also known as heavyweight processes which.
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
Software Design 13.1 From controller to threads l Threads are lightweight processes (what’s a process?)  Threads are part of a single program, share state.
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
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.
Distributed and Parallel Processing George Wells.
Prepared by Oussama Jebbar
Multithreading / Concurrency
Threaded Programming in Python
PROCESS MANAGEMENT IN MACH
Multi Threading.
Multithreading.
Background on the need for Synchronization
Applied Operating System Concepts -
Multithreading.
Threading And Parallel Programming Constructs
Multithreading.
Thread Synchronization
Lecture 2 Part 2 Process Synchronization
Threads Chapter 4.
Concurrency: Mutual Exclusion and Process Synchronization
Threaded Programming in Python
NETWORK PROGRAMMING CNET 441
CS333 Intro to Operating Systems
Ch 3.
Presentation transcript:

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Thread Basics Threading allows multiple activities to coexist within a single process Threads are like processes –Independent, concurrent paths of execution Threads are less insulated –Share memory, file handles, preprocess state

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Why use threads? Make the UI more responsive Take advantage of multiprocessor systems Simplify modeling Perform asynchronous or background processing

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Thread’s Life – Creating Threads Every Java program contains the main thread Additional threads are created through the Thread constructor

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Thread’s Life – Starting a Thread Different than creating a thread Must use start() method

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Thread’s Life – Ending Threads Three ways: 1.End of the run( ) method 2.Throws an Exception or Error that is not caught 3.Another thread calls the stop( ) method

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Joining Threads join( ) method –Waits for the thread to complete –Use when partitioning a larger problem into smaller ones

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Scheduling Timing of thread scheduling and execution is nondeterministic Use synchronization to ensure data consistency Synchronization example

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sleeping sleep( ) method –Cause the current thread to wait until the specified time has elapsed (in milliseconds) or until the thread is interrupted by another thread –When finished waiting, thread goes back onto scheduler’s queue of runnable threads

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Example: Partitioning a large task with multiple threads Use threads to help in a searching algorithm. In-class Example

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Sharing Access to Data Shared variables between threads requires synchronization to prevent inconsistent data –Polling –Synchronization Logger Example –Semaphores

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Basic rule for synchronizing You must synchronize whenever you are: –Reading a variable that may have been last written by another thread –Writing a variable that may be read next by another thread –Modifying multiple related values, you want other threads to see as atomic changes

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Deadlock Occurs when each thread is waiting for an action that one of the others can perform Thread 1 holds a lock on Object A and is waiting for the lock on Object B & Thread 2 holds the lock on Object B and is waiting for the lock on Object A

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Semaphores Control the number of activities that can access certain resources Used to … –Implement resource pools –Impose a bound on a collection

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Semaphores Manages a set of permits Initial number passed to constructor Activities acquire and release permits If no permit is available, acquire blocks until one is.