Processes Creation and Threads. Shared Resource Example The console is just a place where text can be printed by the application currently running. Program.

Slides:



Advertisements
Similar presentations
Operating Systems Mehdi Naghavi Winter 1385.
Advertisements

CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 14: Deadlock & Dinning Philosophers.
CSCC69: Operating Systems
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Mutual Exclusion.
Deadlocks, Message Passing Brief refresh from last week Tore Larsen Oct
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Deadlock CS Introduction to Operating Systems.
IT Systems Multiprocessor System EN230-1 Justin Champion C208 –
Analogue and Digital. Digital and Analogue 1.What change is happening between 2008 and 2012? 2.List some of the ways that digital TV can be sent. 3.List.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Processes CSCI 444/544 Operating Systems Fall 2008.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Review: Process Management Objective: –Enable fair multi-user, multiprocess computing on limited physical resources –Security and efficiency Process: running.
Concurrency: Deadlock and Starvation Chapter 6. Revision Describe three necessary conditions for deadlock Which condition is the result of the three necessary.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
A Introduction to Computing II Lecture 18: Concurrency Issues Fall Session 2000.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Chapter 2.3 : Interprocess Communication
IPC and Classical Synchronization Problems
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
Nachos.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Nachos Phase 1 Code -Hints and Comments
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Games Development 2 Concurrent Programming CO3301 Week 9.
Thread Synchronization Tutorial #8 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
Concurrent Programming and Threads Threads Blocking a User Interface.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Pitfalls: Time Dependent Behaviors CS433 Spring 2001 Laxmikant Kale.
Operating Systems Review ENCE 360.
Chapter 3: Process Concept
Operating systems Deadlocks.
ITEC 202 Operating Systems
Switching Techniques In large networks there might be multiple paths linking sender and receiver. Information may be switched as it travels through various.
Concurrency: Mutual Exclusion and Synchronization
Principles of Software Development
Switching Techniques.
Operating systems Deadlocks.
Scheduling.
Processes Creation and Threads
CSE 451 Section 1/27/2000.
Chapter 3: Process Management
Synchronization and liveness
Presentation transcript:

Processes Creation and Threads

Shared Resource Example The console is just a place where text can be printed by the application currently running. Program writes to the console using system.out.println().

Problem… Any thread calling system.out.println() will result in a message being displayed on the screen. What if there are two threads trying to write messages to the screen at “the same time”?

Realization Only 1 thread can be active at any time. Switching between threads can happen any time in most operating systems.

Sample Thread1() { print “This is the first thread” } Thread2() { print “This is the second thread” } Main() { start Thread1 start Thread2 wait for both threads to finish }

Output on Terminal… Many possibilities…

Problem… Suppose we want Thread B to wait for Thread A before starting.

Solution 1 int turn; Thread1() { print “This is the first thread” turn = 2 } Thread2() { while (turn = 2) ; print “This is the second thread” } Main() { turn = 1 start Thread1 start Thread2 wait for both threads to finish }

Solution 2 int turn; Thread1() { print “This is the first thread” turn = 2 } Thread2() { while (turn = 1) sleep 5 seconds; print “This is the second thread” } Main() { turn = 1 start Thread1 start Thread2 wait for both threads to finish }

Solution 3 int turn; Thread1() { print “This is the first thread” Send signal } Thread2() { wait for signal print “This is the second thread” } Main() { start Thread1 start Thread2 wait for both threads to finish }

Semaphore A variable on which a thread (or process) can wait. The operation wait is often called “take”. The operating sending the signal is often called “give”.

Cell Phone Example Only 1 person can use a phone to call at any given time. If a person wants to make a call they must “take” the phone. When a person is finished they “give” the phone. If a person tries to take the phone and it is currently taken, that person must wait.

Message Queues When 2 people want to exchange information they often use SMS messages. When 2 threads (or processes) want to exchange information they rely on messaging techniques.

SMS Messages In box SenderReceiver The inbox can store many messages.

SMS Messages Message queue The message queue is like an inbox but is often part of the OS Sending Process Receiving Process

Observations Multiple senders to a single receiver is easy. Having multiple receivers using the same message queue is not simple. Most systems allow for high priority messages to be sent. Most systems allow receiver to block waiting for a message. If the receiver isn’t looking, they won’t know they have a message.

Problem… There are 4 students sitting around a table. There are 4 phones arranged between each pair of students. Students sleep for a random amount of time, then they decide to make a phone call.

Continued. To make a phone call each student must use 2 phones at the same time. Students can only pick up 1 phone at a time and must start with the left phone. If a phone is not available the student must wait. Once a phone is picked up, the student will hang onto it until they done with their call.

Picture

The problem… If all students wake up at the same time and decide to make a phone call: –All students pick up the left phone and will wait for the right phone. –The right phone will never be available. This is called “deadlock”. In big cities with traffic problems there is often called “gridlock”.

In computing If a process acquires 1 resource (takes) and waits forever for a second resource without giving up the first, you have the potential for deadlock. Detecting and preventing is difficult! Not a subject for this class.