Homework 3-4 Sarah Diesburg Operating Systems COP 4610.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Synchronization NOTE to instructors: it is helpful to walk through an example such as readers/writers locks for illustrating the use of condition variables.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Interprocess Communication
Bash startup files Linux/Unix files stty 1.  midterms  bash startup files  stty 2.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Guide To UNIX Using Linux Third Edition
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
9/8/2015cse synchronization-p1 © Perkins DW Johnson and University of Washington1 Synchronization Part 1 CSE 410, Spring 2008 Computer Systems.
Semaphores and Bounded Buffer Andy Wang Operating Systems COP 4610 / CGS 5765.
Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University.
Implementing Synchronization. Synchronization 101 Synchronization constrains the set of possible interleavings: Threads “agree” to stay out of each other’s.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Linux Operations and Administration
Semaphores and Bounded Buffer. Semaphores  Semaphore is a type of generalized lock –Defined by Dijkstra in the last 60s –Main synchronization primitives.
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
Introduction to Unix Shell & Scripting with csh/tcsh  Brief Unix History  Unix Shell & Flavor  CSH/TCSH Scripts.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
Homework & Practical Let’s go through it Does anyone not have access to the wiki? Questions?
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Practice Chapter Five.
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
Homework 3-4 Sarah Diesburg Operating Systems COP 4610.
ULI101 Week 10. Lesson Overview ● Shell Start-up and Configuration Files ● Shell History ● Alias Statement ● Shell Variables ● Introduction to Shell Scripting.
CS703 - Advanced Operating Systems
SUSE Linux Enterprise Desktop Administration
Shell Features CSCI N321 – System and Network Administration
Sarah Diesburg Operating Systems COP 4610
CS703 – Advanced Operating Systems
Background on the need for Synchronization
Monitors, Condition Variables, and Readers-Writers
Shell Environments.
Introduction to Operating Systems
CHAPTER 8 (skip , ) CHAPTER 10
Sarah Diesburg Operating Systems COP 4610
Andy Wang Operating Systems COP 4610 / CGS 5765
Semaphores and Bounded Buffer
Process Synchronization
Implementing Mutual Exclusion
Linux Shell Script Programming
Implementing Mutual Exclusion
Unix Shell Environments
CMPSC 60: Week 5 Discussion
Review The Critical Section problem Peterson’s Algorithm
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Homework 3-4 Sarah Diesburg Operating Systems COP 4610

1. All Possible Execution Orders Thread AThread B x = 3;y = 2; x = y - 1;y = x + 1; x = 3y = 2x = y - 1y = 2 y = x + 1 x = y - 1y = x + 1 x = y - 1 x = 3y = x + 1 x = 3 x = y - 1 (x = ?, y = ?) (x = 3, y = ?) (x = ?, y = ?) (x = ?, y = 2) (x = ?, y = ?) (x = 3, y = 2) (x = ?, y = 2) (x = ?, y = ?) (x = 1, y = 2) (x = 3, y = 4) (x = 3, y = ?) (x = ?, y = ?)

2. Why does disabling interrupts not work on multi-processors? Interrupts are disabled on a per-CPU basis A thread running on another CPU could enter the critical area

3. Too Much Milk w/ Busy Waits //define the busy-wait locks value = 0; Lock::Acquire() { // while the previous value is BUSY, loop while (test_and_set(value) == 1); } Lock::Release() { value = 0; }

3. (cont.) //Dumb Lock::Acquire(value) if(no milk) { //go get milk Lock::Release(value) //Dumber Lock::Acquire(value) if(no milk) { //go get milk Lock::Release(value)

4. Does this work? // consumer waits on 0 semaphore nLoadedBuffers = 0; // producer waits on 0 semaphore nFreeBuffers = N; // N >= 2 // one thread waits when another thread is // modifying the buffer semaphore mutex = 1; Producer() { 1. P(nFreeBuffers); 2. P(mutex); 3. // put 1 item in the buffer 4. V(nLoadedBuffers); 5. V(mutex); } Consumer() { 6. P(nLoadedBuffers); 7. P(mutex); 8. // take 1 item from the buffer 9. V(mutex); 10. V(nFreeBuffers); }

4. Does this work? // consumer waits on 0 semaphore nLoadedBuffers = 0; // producer waits on 0 semaphore nFreeBuffers = N; // N >= 2 // one thread waits when another thread is // modifying the buffer semaphore mutex = 1; Producer() { 1. P(nFreeBuffers); 2. P(mutex); 3. // put 1 item in the buffer 4. V(nLoadedBuffers); 5. V(mutex); } Consumer() { 6. P(nLoadedBuffers); 7. P(mutex); 8. // take 1 item from the buffer 9. V(mutex); 10. V(nFreeBuffers); }

4. Does this work? Actually, yes. Even if producer thread hits #4 and wakes up a consumer sleeping on #6, the consumer will not be able to enter the critical section until the producer comes back and hits #5

Additional Things

Race Conditions – An anology Suppose there is a bag of chips in the kitchen at home and I want to make “walking tacos” for dinner

Race Conditions – An anology Suppose there is a bag of chips in the kitchen at home and I want to make “walking tacos” for dinner If my husband gets home first, the bag of chips will be consumed before dinner  My dinner plans are foiled! If I get home first, I can use the bag of chips for dinner

$PATH My $PATH: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games Shell (or exec call) searches every path for the name of the program you just called  It then executes the first matching program found Adding a :. to the end of your path tells the shell that you want to execute programs found in your current directory automatically

Bash Files.bash_history  Contains a history of all your bash commands.bash_logout  Script that is executed when you log out  Current script clears your console  Can add anything here

Bash Files.bash_profile and.bashrc  Both contain scripts to set up environment when logging in .bash_profile actually calls.bashrc Also calls.firstlogin – what do you think that is for? Modifies $PATH as well .bashrc Non-login prompts Sets some variables, shell prompt, aliases (shortcuts)

Shell Files So where does $PATH actually come from? On this system, /etc/profile  /etc directory holds system-wide configurations  The profile file is universal to any shell you run /bin/bash, /bin/sh, /bin/ksh, …

Shell Files So, where would you want to modify path if you wanted to  Change it for all users?  Change it for just yourself?