Andy Wang Operating Systems COP 4610 / CGF 5765

Slides:



Advertisements
Similar presentations
COSC513 Operating System Research Paper Fundamental Properties of Programming for Parallelism Student: Feng Chen (134192)
Advertisements

Threads. What do we have so far The basic unit of CPU utilization is a process. To run a program (a sequence of code), create a process. Processes are.
Race Conditions. Isolated & Non-Isolated Processes Isolated: Do not share state with other processes –The output of process is unaffected by run of other.
Continuously Recording Program Execution for Deterministic Replay Debugging.
CSCE 212 Quiz 4 – 2/16/11 *Assume computes take 1 clock cycle, loads and stores take 10 cycles and branches take 4 cycles and that they are running on.
CS Parallelism Dr. Vicki H. Allan. 2 Concurrency Concurrency can occur at four levels: 1.Machine instruction level – may have both an adder and a multiplier.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
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.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
CPS110: Intro to processes, threads and concurrency Author: Landon Cox.
Concurrency: Threads, Address Spaces, and Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
Exam Review Andy Wang Operating Systems COP 4610 / CGS 5765.
Threaded Programming Lecture 1: Concepts. 2 Overview Shared memory systems Basic Concepts in Threaded Programming.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CPS110: Intro to processes Landon Cox. OS Complexity  Lines of code  XP: 40 million  Linux 2.6: 6 million  (mostly driver code)  Sources of complexity.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Agenda  Quick Review  Finish Introduction  Java Threads.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
1 Introduction to Threads Race Conditions. 2 Process Address Space Revisited Code Data OS Stack (a)Process with Single Thread (b) Process with Two Threads.
6/27/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
CS 162 Discussion Section Week 2. Who am I? Prashanth Mohan Office Hours: 11-12pm Tu W at.
Basic concepts of C++ Presented by Prof. Satyajit De
Lecture 3 Process.
Topic 3 (Textbook - Chapter 3) Processes
Introduction to the C Language
Sarah Diesburg Operating Systems COP 4610
Background on the need for Synchronization
Andy Wang COP 5611 Advanced Operating Systems
COMPSCI210 Recitation 12 Oct 2012 Vamsi Thummala
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process Concept
What should we teach regarding…
The Processor and Machine Language
Applied Operating System Concepts
Turing Machines Acceptors; Enumerators
Concurrency: Threads, Address Spaces, and Processes
CGS 3763 Operating Systems Concepts Spring 2013
Introduction to the C Language
Computer Organization & Compilation Process
Code Generation.
One-Dimensional Array Introduction Lesson xx
Concurrency: Threads, Address Spaces, and Processes
COP 4600 Operating Systems Spring 2011
COP 4600 Operating Systems Fall 2010
Process & its States Lecture 5.
COT 5611 Operating Systems Design Principles Spring 2012
Grades.
Implementing Mutual Exclusion
Concurrency: Mutual Exclusion and Process Synchronization
Function “Inputs and Outputs”
2P13 Week 3.
Implementing Mutual Exclusion
Race Conditions David Ferry CSCI 3500 – Operating Systems
CS703 - Advanced Operating Systems
Creating and Using Pointer Variables in C++ By: Ed Brunjes
Andy Wang Operating Systems COP 4610 / CGS 5765
Andy Wang Operating Systems COP 4610 / CGS 5765
COP 4600 Operating Systems Fall 2010
Andy Wang Operating Systems COP 4610 / CGF 5765
Computer Organization & Compilation Process
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Problems with Locks Andrew Whitaker CSE451.
EECE.4810/EECE.5730 Operating Systems
Andy Wang Operating Systems COP 4610 / CGS 5765
Sarah Diesburg Operating Systems COP 4610
Concurrency: Threads, Address Spaces, and Processes
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Andy Wang Operating Systems COP 4610 / CGF 5765 Cooperating Threads Andy Wang Operating Systems COP 4610 / CGF 5765

Independent Threads No states shared with other threads Deterministic computation Output depends on input Reproducible Output does not depend on the order and timing of other threads Scheduling order does not matter e.g., gif2jpeg

Cooperating Threads Shared states Nondeterministic Nonreproducible e.g., elevator controllers Example: 2 threads sharing the same display Thread A Thread B cout << “ABC”; cout << “123”; You may get “A12BC3”

So, Why Allow Cooperating Threads?

So, Why Allow Cooperating Threads? Shared resources e.g., a single processor Speedup Occurs when threads use different resources at different times Modularity An application can be decomposed into threads

Some Concurrent Programs If threads work on separate data, scheduling does not matter Thread A Thread B x = 1; y = 2;

Some Concurrent Programs If threads share data, the final values are not as obvious Thread A Thread B x = 1; y = 2; x = y + 1; y = y * 2; What are the indivisible operations?

Atomic Operations An atomic operation always runs to completion; it’s all or nothing e.g., memory loads and stores on most machines Many operations are not atomic Double precision floating point store

Suppose… Each C statement is atomic Let’s revisit the example…

All Possible Execution Orders Thread A Thread B x = 1; y = 2; x = y + 1; y = y * 2; x = 1 y = 2 x = y + 1 y = 2 x = 1 y = y * 2 y = 2 y = y * 2 x = y + 1 y = y * 2 x = 1 x = y + 1 A decision tree

All Possible Execution Orders Thread A Thread B x = 1; y = 2; x = y + 1; y = y * 2; (x = ?, y = ?) (x = ?, y = 2) (x = 1, y = ?) x = 1 y = 2 (x = 1, y = 2) (x = ?, y = ?) (x = ?, y = 4) x = y + 1 y = 2 x = 1 y = y * 2 (x = ?, y = 2) (x = 3, y = 2) (x = 1, y = 4) (x = 1, y = 4) x = 1 y = 2 x = y + 1 y = y * 2 x = y + 1 y = y * 2 y = y * 2 x = y + 1 (x = ?, y = 4) (x = 3, y = 4) (x = 5, y = 4) (x = 5, y = 4)

Another Example Assume each C statement is atomic Both threads are in the same address space Thread A Thread B j = 0; j = 0; while (j < 10) { while (j > -10) { ++j; --j; } } cout << “A wins”; cout << “B wins”;

So… Who wins? Can the computation go on forever? Race conditions occur when threads share data, and their results depend on the timing of their executions…