Discussion CSE 224. Week 4

Similar documents
Concurrency: a crash course

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Synchronization for Concurrent Tasks

POSIX Threads: a first step toward parallel programming. George Bosilca

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (II)

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Operating systems. Lecture 3 Interprocess communication. Narcis ILISEI, 2018

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Midterm Exam. October 20th, Thursday NSC

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Mutual Exclusion and Synchronization

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

CS 3305 Intro to Threads. Lecture 6

CSE 374 Programming Concepts & Tools

IT 540 Operating Systems ECE519 Advanced Operating Systems

CGI Architecture Diagram. Web browser takes response from web server and displays either the received file or error message.

Le L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading

Concurrency, Thread. Dongkun Shin, SKKU

CS153: Deadlock. Chengyu Song. Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian

Syllabus CSCI 405 Operating Systems Fall 2018

Operating Systems. Thread Synchronization Primitives. Thomas Ropars.

Lecture 9: Midterm Review

High Performance Computing Course Notes Shared Memory Parallel Programming

CS533 Concepts of Operating Systems. Jonathan Walpole

CSE 153 Design of Operating Systems

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Operating Systems : Overview

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)

CSE 4/521 Introduction to Operating Systems

CS370 Operating Systems Midterm Review

연세대학교전기전자공학과프로세서연구실박사과정김재억.

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

Parallelization and Synchronization. CS165 Section 8

The University of Texas at Arlington

CSE Traditional Operating Systems deal with typical system software designed to be:

Multiprocessor System. Multiprocessor Systems. Bus Based UMA. Types of Multiprocessors (MPs) Cache Consistency. Bus Based UMA. Chapter 8, 8.

UNIT:2. Process Management

CS510 Operating System Foundations. Jonathan Walpole

Administrivia. HW1 due Oct 4. Lectures now being recorded. I ll post URLs when available. Discussing Readings on Monday.

Multiprocessor Systems. COMP s1

User Space Multithreading. Computer Science, University of Warwick

Lecture 15: I/O Devices & Drivers

The University of Texas at Arlington

CSE 153 Design of Operating Systems Fall 2018

Martin Kruliš, v

Concurrency. Glossary

Survey feedback. 2/26/08 CSE 30341: Operating Systems Principles

Verteilte Systeme (Distributed Systems)

Dealing with Issues for Interprocess Communication

CSE 451 Midterm 1. Name:

Synchronization I. Jo, Heeseung

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

ECE 574 Cluster Computing Lecture 8

CSE 153 Design of Operating Systems

CS-537: Midterm Exam (Spring 2001)

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Distributed Information Processing

CIS192 Python Programming

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Threads Chapter 4. Reading: 4.1,4.4, 4.5

multiprocessing HPC Python R. Todd Evans January 23, 2015

Lecture 5: Synchronization w/locks

OS Structure. User mode/ kernel mode. System call. Other concepts to know. Memory protection, privileged instructions

Introduction to Locks. Intrinsic Locks

PROCESS SYNCHRONIZATION

CS510 Advanced Topics in Concurrency. Jonathan Walpole

CS450/550 Operating Systems

AC59/AT59/AC110/AT110 OPERATING SYSTEMS & SYSTEMS SOFTWARE DEC 2015

CSE 486/586 Distributed Systems

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

POSIX / System Programming

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1

CS 153 Design of Operating Systems Winter 2016

Parallel And Distributed Compilers

CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

G52CON: Concepts of Concurrency

UNIVERSITY OF NEBRASKA AT OMAHA COURSE SYLLABUS/DESCRIPTION

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

CS450/550 Operating Systems

CSE 333 Lecture 1 - Systems programming

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Java Memory Model. Jian Cao. Department of Electrical and Computer Engineering Rice University. Sep 22, 2016

CSE 333 Lecture 1 - Systems programming

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Programmazione Avanzata e Paradigmi Ingegneria e Scienze Informatiche - UNIBO a.a 2013/2014 Lecturer: Alessandro Ricci

More on Synchronization and Deadlock

CS333 Intro to Operating Systems. Jonathan Walpole

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

CS 3723 Operating Systems: Final Review

Threads Questions Important Questions

Processes and Threads

Concurrent & Distributed Systems Supervision Exercises

Streaming Data And Concurrency In R

Operating System Architecture. CS3026 Operating Systems Lecture 03

Processes and Threads

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

CS 261 Fall Mike Lam, Professor. Threads

Transcription:

Discussion CSE 224 Week 4

Midterm The midterm will cover - 1. Topics discussed in lecture 2. Research papers from the homeworks 3. Textbook readings from Unit 1 and Unit 2

HW 3&4 Clarifications 1. The client will not request a directory, except for the case where the request is of the type - GET / HTTP/1.1 In which case you have to return /index.html 2. As mentioned in the spec, the clients will only request jpeg, png and html file types

What is Concurrency Concurrency is the ability of an algorithm or program to run more than one task such that their progress overlaps in time. Concurrency does not necessarily mean parallelism.

2 Different approaches for Web server Multi-threaded approach: a new thread for each incoming connection Multi-process approach: will create a new process to handle an incoming web request

Multithreading

What is a thread? The smallest sequence of programmed instructions that can be managed independently by an OS scheduler When starting a program, a process is created. Every process has a unique set of virtual memory, files, code and resources. A process consists of one or more threads that run the code. Every thread in a process accesses the same memory while running. When changing the value of a global variable in one thread, all threads then see the new value.

Process vs Thread A thread is Lightweight It is a Unit of CPU utilization while process is a unit of Resource Allocation Multithreading faster than Multiprocessing. Threads have shared memory while processes use IPC A thread belongs to a process

Single-threaded vs Multi-threaded

Creating threads in python Multi-threaded programs using the threading module - 1. The Global Interpreter Lock and its implications - a. Only one thread can take a lock on the python interpreter, i.e only one thread can be in the state of execution at a time. b. This is done because python uses reference counting to manage memory. c. This is a problem in CPU bound multi-threaded programs but for IO bound applications like the HW4 server we can use this module.

GIL

Threading module and thread module The threading module builds on top of the thread (or _thread) module in python For hw4 you can work with the threading module

Creating a thread in python threading.thread(group=none, target=none, name=none, args=(), kwargs={}, *, daemon=none) 1. group - this is for future implementations and can be ignored for now. 2. target - the function that you want to invoke as a separate thread 3. name - a unique name for each thread, defaults to Thread-N 4. args - the tuple of arguments that will be passed to target, pass in comma separated variables 5. kwargs - a dictionary of keyword arguments for the target invocation. 6. daemon - whether thread is daemonic, i.e whether it runs in background

Python example

Race condition Race condition is a condition where the outcome of the program depends on the relative execution order of one or more threads. Simple lines of code often require several assembly instructions to implement. Strange behavior in concurrent programs is usually caused by a race condition. A race condition is when multiple threads try to access the same data simultaneously. The final result of a race condition is unpredictable.

Race condition: Example

Race condition: Example

Race condition: Example

Race condition: Example

Race condition: Example

Race condition: Example

Race condition: Example

Race condition: Example

Synchronization and locks To avoid race conditions, we need to use synchronization. Synchronization uses special objects to make threads work in unison. These objects are called synchronization primitives. These primitives have invariants that make it possible to avoid race conditions. The simplest object is a lock, and is usually called a mutex ( mutual exclusion ).

Mutexes A mutex has two states: locked, and unlocked. A thread that has locked a mutex is said to be holding the lock. A mutex has certain rules, or invariants: Only one thread can hold a lock at a time. A mutex can only be locked if it is currently unlocked. Only the thread holding the lock can unlock the mutex. A thread trying to lock an already locked mutex must wait until it is unlocked. This prevents other threads from modifying objects at the same time.

Deadlocks A deadlock is a state, in which at least two threads are blocked, because each thread is waiting for release of some resource with which other thread works, before it releases its own resource.

Multiprocessing in python Multiprocessing using the multiprocessing module in python The API exposed is very similar to the threading module Spawns separate processes instead of threads.

multiprocessing