Parallelism and Concurrency

Slides:



Advertisements
Similar presentations
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
Advertisements

CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
Chapter Hardwired vs Microprogrammed Control Multithreading
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Memory Consistency Models Some material borrowed from Sarita Adve’s (UIUC) tutorial on memory consistency models.
© 2009 Matthew J. Sottile, Timothy G. Mattson, and Craig E Rasmussen 1 Concurrency in Programming Languages Matthew J. Sottile Timothy G. Mattson Craig.
Operating System Review September 10, 2012Introduction to Computer Security ©2004 Matt Bishop Slide #1-1.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
CSE 425: Concurrency III Monitors A monitor is a higher level construct for synchronizing multiple threads’ access to a common code segment –Can implement.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
The Relational Model1 Transaction Processing Units of Work.
Memory Consistency Models. Outline Review of multi-threaded program execution on uniprocessor Need for memory consistency models Sequential consistency.
CSE 425: Concurrency II Semaphores and Mutexes Can avoid bad inter-leavings by acquiring locks –Guard access to a shared resource to take turns using it.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
Threads Tutorial #7 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers – It is.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Debugging Threaded Applications By Andrew Binstock CMPS Parallel.
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.
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.
3/12/2013Computer Engg, IIT(BHU)1 OpenMP-1. OpenMP is a portable, multiprocessing API for shared memory computers OpenMP is not a “language” Instead,
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
December 1, 2006©2006 Craig Zilles1 Threads & Atomic Operations in Hardware  Previously, we introduced multi-core parallelism & cache coherence —Today.
Java Thread Programming
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
6 July 2015 Charles Reiss
Threads & Multithreading
Processes and threads.
Names and Attributes Names are a key programming language feature
Memory Consistency Models
COMPSCI210 Recitation 12 Oct 2012 Vamsi Thummala
Atomic Operations in Hardware
Atomic Operations in Hardware
Critical sections, locking, monitors, etc.
Memory Consistency Models
Computer Engg, IIT(BHU)
Chapter 4 Threads.
143a discussion session week 3
Chapter 4 Multithreading programming
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Changing thread semantics
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Chapter 26 Concurrency and Thread
Multithreading.
Iteration Implemented through loop constructs (e.g., in C++)
Thread Implementation Issues
Threads Chapter 4.
Dr. Mustafa Cem Kasapbaşı
Multithreaded Programming
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Concurrency: Mutual Exclusion and Process Synchronization
Memory Consistency Models
Semester Review Brian Kocoloski
Kernel Synchronization II
Why Threads Are A Bad Idea (for most purposes)
- 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,
CS333 Intro to Operating Systems
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
CS703 – Advanced Operating Systems
Operating Systems Concepts
CSE 332: Concurrency and Locks
Threads CSE451 Andrew Whitaker TODO: print handouts for AspectRatio.
Chapter 3: Process Management
Presentation transcript:

Parallelism and Concurrency Two different terms for potential vs. actual parallelism Actual parallelism (called parallelism) is when code can execute in physically parallel hardware E.g., on multiple hosts, or on multiple cores of the same host Can achieve significant speedup in program execution times Must communicate to aggregate results, which slows things down Logical parallelism (called concurrency) is when code appears parallel but may be interleaving on the same core E.g., part of one code sequence runs, then part of another, etc. Parallelism and concurrency share some key issues E.g., asynchrony and interleaving of what happens when May need to represent sequence and/or timing semantics May need special handling to avoid semantic hazards

Concurrency and Synchronization Issues Two concurrent or parallel activities may be “racing” to reach a code section involving a shared resource E.g., thread 1 does x=A; then y=B; and thread 2 does x=C; then y=D; but the statements inter-leave to produce x==C and y==B (which may be an invalid state) Bad inter-leavings can be avoided via synchronization E.g., each thread waits for a lock on the critical section before writing so either x==A && y==B or x==C && y==D However, synchronization can lead to deadlock E.g., thread 1 takes lock 1 and needs lock 2, thread 2 takes lock 2 and needs lock one (called a deadly embrace) Protocols must be followed to avoid or break deadlock E.g., each thread acquires lock 1 before attempting lock 2

Processes vs. Threads With modern hardware, protecting the memory etc. used by a program is valuable for reliability E.g., each program runs in a process with its own memory, and any attempt to access another’s memory crashes it Inter-program parallelism is thus made more reliable May want intra-program parallelism/concurrency too E.g., to divide and conquer a matrix multiplication, etc. Offers potential performance gains if costs can be kept low Threads offer much lower context switching costs Don’t have to save and restore memory areas, just program counter and stack (may optimize stack in some languages) Can achieve true parallelism with threads, e.g., by binding them to different cores either statically or dynamically

Today’s Studio Exercises We’ll code up ideas from Scott Chapter 12.1 and 12.2 Using threads to run different code sequences concurrently Looking at safe vs. unsafe cases involving multithreading Today’s exercises are in C++ Please take advantage of the on-line tutorial and reference manual pages that are linked on the course web site The provided Makefile also may be helpful for enrichment As always, please ask for help as needed When done, send e-mail with your answers to cse425@seas.wustl.edu, with subject line “Concurrency Studio I”