CS240: Advanced Programming Concepts

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

CS533 Concepts of Operating Systems Class 2 The Duality of Threads and Events.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Processor Architecture
Threads. Readings r Silberschatz et al : Chapter 4.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
1.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 1: Introduction What Operating Systems Do √ Computer-System Organization.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Processes and threads.
Asynchronous Task (AsyncTask) in Android
Reactive Android Development
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
CS 6560: Operating Systems Design
Operating Systems (CS 340 D)
Sujata Ray Dey Maheshtala College Computer Science Department
Lecture Topics: 11/1 Processes Process Management
Multithreaded Programming in Java
CS399 New Beginnings Jonathan Walpole.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 3 Threads and Multithreading
Async or Parallel? No they aren’t the same thing!
Chapter 4: Multithreaded Programming
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process-Concept
Lecture 21 Concurrency Introduction
Assembly Language for Intel-Based Computers, 5th Edition
Intro to Processes CSSE 332 Operating Systems
Architecture Background
Operating Systems (CS 340 D)
Chapter 4: Threads.
Operating System Concepts
Chapter 4 Multithreading programming
Chapter 4: Threads.
Lecture 2: Processes Part 1
Android Programming Lecture 8
ICS 143 Principles of Operating Systems
Chapter 4: Threads.
Multithreading.
CS371m - Mobile Computing Responsiveness.
Operating System Concepts
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads and Concurrency
Threads Chapter 4.
CSCE 313 – Introduction to UNIx process
Android Topics Asynchronous Callsbacks
Sujata Ray Dey Maheshtala College Computer Science Department
Multithreaded Programming
Android Developer Fundamentals V2
PROCESSES & THREADS ADINA-CLAUDIA STOICA.
CS703 – Advanced Operating Systems
Chapter 3: Processes.
Chapter 4: Threads & Concurrency
Chapter 4: Threads.
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
Chapter 3: Processes Process Concept Process Scheduling
Operating System Overview
Chapter 4:Threads Book: Operating System Principles , 9th Edition , Abraham Silberschatz, Peter Baer Galvin, Greg Gagne.
Presentation transcript:

CS240: Advanced Programming Concepts Screencast #2

Multi-Threaded Execution and AsyncTask An Introduction

What is a computer program? A collection of instructions and data A set of related tasks that we desire the computer to perform for us

Concurrent vs. Parallel Processing Concurrent or “Overlapped” execution Multiple processes are accomplishing work over a period of time, though not necessarily executing at the same moment (i.e. interleaved execution) Parallel execution Multiple processes are in execution at the same moment

CPUs can take advantage of instruction level parallelism at runtime… 1: A = 6 + B; 2: C = A / 2; 3: D = C * 5; 4: E = A * B; 5: F = B / 2; Pipelining Superscalar (i.e. multi-issue pipeline) Out of order execution Etc.

CPU’s have more difficulty taking advantage of “task” level parallelism – Enter Multiprocessing … Multiprocessing (OS enabled) Multiple processes take turns utilizing the CPU (A program will be comprised of one or more processes) Processes that ask to do something that takes a while (such as retrieve data from a large-but-slow storage device) are blocked until the requested data etc. is ready – they surrender some or all of their turn while their request is being processed, allowing a process that is ready to make use of the time… Multi-core + multiprocessing: Same idea spread across multiple cores… A process that is capable of doing more than one of its tasks at a time does not benefit from multi-processing alone

Multiprocessing cont. Limitations: Human partitioning is needed… Processes are “heavy” Swapping them in and out requires a complete context switch Inter-process communication is expensive compared to intra-process communication Diminishing returns… Missed opportunities - Programs/processes may be capable of doing other portions of their work while waiting on a request that causes them to be blocked/stalled

For example… CPU’s cannot identify tasks, nor effectively determine when, where, or how synchronization can or should be performed at the task level

Threads: A way of splitting a process into “mini-processes” On single core CPU If one thread “blocks” other threads may utilize its CPU time Shared memory (communication is efficient) No need for a full context switch On multiple cores Multiple threads may be executing in parallel on multiple cores *We are ignoring a lot of details here, such as the mechanism for passing information between threads 1 and 2, and how this information is synchronized etc. but our purpose at the moment is simply to understand the main idea…

Android Apps Always have at least one thread (duh) – the UI thread Responds to asynchronous events: Touch… System events… Etc. Android doesn’t like to be ignored by this thread…: “App isn’t responding. Do you want to close it?” Accessing the internet is slow…. Android doesn’t allow us to access the internet from the UI thread….

Using the AsyncTask Class to run background tasks in Android Intended for short, single execution tasks. Use other approaches if you need long running threads in the background. Perfect for our purposes in Family Map Login to the server… Retrieve appropriate data… Extend this class to execute a task on a separate thread in the background onPreExecute() doInBackground() onProgressUpdate() onPostExecute() https://developer.android.com/reference/android/os/AsyncTask.html

A closer look…

Rules To Observe… “Threading rules There are a few threading rules that must be followed for this class to work properly: The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN. The task instance must be created on the UI thread. execute(Params...) must be invoked on the UI thread. Do not call onPreExecute(), onPostExecute(Result), doInBackground(Params...), onProgressUpdate(Progress...) manually. The task can be executed only once (an exception will be thrown if a second execution is attempted.)” [ https://developer.android.com/reference/android/os/AsyncTask.html ]