CSC 480 - Multiprocessor Programming, Spring, 2012 Chapter 8 – Applying Thread Pools Dr. Dale E. Parson, week 10.

Slides:



Advertisements
Similar presentations
Practical Session 6 Multitasking vs. multithreading Threads Concurrency vs. Parallelism Java Threads Thread confinement Object/Class Immutability.
Advertisements

Concurrency (p2) synchronized (this) { doLecture(part2); } synchronized (this) { doLecture(part2); }
50.003: Elements of Software Construction Week 10 Thread Pool.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
CSC Multiprocessor Programming, Spring, 2011 Outline for Chapter 6 – Task Execution Dr. Dale E. Parson, week 7.
50.003: Elements of Software Construction Week 11 Pitfalls and Testing and Parallelization.
CSC Multiprocessor Programming, Spring, 2011 Outline for Chapter 5 – Building Blocks – Library Classes, Dr. Dale E. Parson, week 5.
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Designing a thread-safe class  Store all states in public static fields  Verifying thread safety is hard  Modifications to the program hard  Design.
Ceng Operating Systems Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 2 nd Edition Chapter 4: Threads.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Lecture 10 – Using Thread Pools Housekeeping:  exam return Monday  Programming assignment on Monday Purpose: practice use of the mechanisms we’ve discussed.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Concurrency, Threads, and Events Robbert van Renesse.
Spring 2002Real-Time Systems (Shin) Rate Monotonic Analysis Assumptions – A1. No nonpreemptible parts in a task, and negligible preemption cost –
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Task Scheduling for Highly Concurrent Analytical and Transactional Main-Memory Workloads Iraklis Psaroudakis (EPFL), Tobias Scheuer (SAP AG), Norman May.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Scheduling and Tasks Spring scheduling.
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.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
1 Multiprocessor and Real-Time Scheduling Chapter 10 Real-Time scheduling will be covered in SYSC3303.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Concurrency Patterns Emery Berger and Mark Corner University.
1 (Worker Queues) cs What is a Thread Pool? A collection of threads that are created once (e.g. when a server starts) That is, no need to create.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 24 th, 2010 The University of Georgia.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
1 Real-Time Scheduling. 2Today Operating System task scheduling –Traditional (non-real-time) scheduling –Real-time scheduling.
CSC Multiprocessor Programming, Spring, 2011 Chapter 9 – GUI Applications Dr. Dale E. Parson, week 11.
Silberschatz and Galvin  Chapter 3:Processes Processes –State of a process, process control block, –Scheduling of processes  Long term scheduler,
Distributed Systems 2 Distributed Processing. Process A process is a logical representation of a physical processor that executes program code and has.
Martin Kruliš by Martin Kruliš (v1.1)1.
Threaded Programming Lecture 1: Concepts. 2 Overview Shared memory systems Basic Concepts in Threaded Programming.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Unit 4: Processes, Threads & Deadlocks June 2012 Kaplan University 1.
Uses some of the slides for chapters 3 and 5 accompanying “Introduction to Parallel Computing”, Addison Wesley, 2003.
Uniprocessor Process Management & Process Scheduling Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi.
L6: Threads “the future is parallel” COMP206, Geoff Holmes and Bernhard Pfahringer.
CSC Multiprocessor Programming, Spring, 2012 Chapter 10 – Avoiding Liveness Hazards Dr. Dale E. Parson, week 11.
…in java DThread Pools x. Thread Pools: Why? Source code updates – copy/paste of run/runnable method for each thread is exhausting There is overhead to.
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.
CSC Multiprocessor Programming, Spring, 2012 Chapter 12 – Testing Concurrent Programs Dr. Dale E. Parson, week 12.
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
A brief intro to: Parallelism, Threads, and Concurrency
OPERATING SYSTEM CONCEPT AND PRACTISE
Thread Pools (Worker Queues) cs
CPU SCHEDULING.
Thread Pools (Worker Queues) cs
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
CSC Multiprocessor Programming, Spring, 2012
Operating System (013022) Dr. H. Iwidat
CSC Multiprocessor Programming, Spring, 2011
Chapter 2.2 : Process Scheduling
Lecture 21: Introduction to Process Scheduling
OverView of Scheduling
TDC 311 Process Scheduling.
Lecture 21: Introduction to Process Scheduling
Uniprocessor Process Management & Process Scheduling
Scheduling 21 May 2019.
Introduction to OS (concept, evolution, some keywords)
Chapter 4: Threads.
Uniprocessor Process Management & Process Scheduling
CSC Multiprocessor Programming, Spring, 2011
Presentation transcript:

CSC Multiprocessor Programming, Spring, 2012 Chapter 8 – Applying Thread Pools Dr. Dale E. Parson, week 10

Types of tasks requiring specific execution policies Dependent tasks Interacting tasks require more careful execution management than independent tasks. The Executor must manage their interaction dynamics. Tasks that exploit thread confinement may require a single- threaded Executor. Response-time-sensitive tasks require sufficient parallelism for responsiveness. Current latency-driven assignment. ThreadLocal should not be used in pool threads to communicate values between tasks.

Thread Starvation Deadlock Executing interdependent tasks in an Executor may lead to thread starvation deadlock if the Executor schedules tasks in a way that causes waits on tasks that never run. Long running tasks can cause responsiveness problems for thread pools. Sizing thread pools N threads = N cpu x U cpu * (1 + W / C) where N cpu is number of CPUs, U cpu is target CPU utilization, 0 <= U cpu <= 1 W / C is ratio of wait time to compute time

Configuring ThreadPoolExecutor ThreadPoolExecutor is the base implementation for cached thread pool, fixed thread pool, and scheduled executor. It supports configuration of core and max pool sizes, keep alive time, a work queue, a thread factory, and a rejected execution handler. Creating and maintaining a custom Executor is complicated.

ThreadPoolExecutor Heuristics LinkedBlockQueue is the default. It does not throttle back the task submitter(s). A bounded queue throttles back submitters. A large bounded queue coupled with a small thread pool reduces memory usage, CPU usage and context switching, potentially at the cost of throughput. Use a Semaphore to throttle submitter threads. For large or unbounded pools SyncronousQueue is an option. It is practical only if the pool is effectively unbounded or if rejecting excess tasks is acceptable. – Bounding the thread pool or work queue is suitable only when tasks are independent.

Saturation Policies Full bounded work queue == saturation. Abort policy causes execute to throw unchecked RejectedExecutionException. Caller-runs policy borrows the submitting thread instead of using a pool thread. Discard policy silently discards submissions. Discard oldest policy silently discards the oldest waiting submission, retries execute.

ThreadFactory and Thread subclasses Custom Thread subclass with extensions. Build an UncaughtExceptionHandler. Debug logging. Set up custom ThreadLocal data. ThreadPoolExecutor can be customized after construction. It can be subclassed to extend beforeExecute and afterExecute to add logging, timing, monitoring or statistics gathering.

Parallelizing recursive algorithms See examples from Summer 2010 handout. Loop parallelization. void processSequentially(List elements) { for (Element e : elements) process(e); } void processInParallel(Executor exec, List elements) { for (final Element e : elements) exec.execute(new Runnable() { public void run() { process(e); } }); }