מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return 0; 9. }

Size: px
Start display at page:

Download "מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return 0; 9. }"

Transcription

1 שאלה : (4 נקודות) א. ב. ג. (5 נקודות) הגדירו את המונח race-condition במדוייק לא להשמיט פרטים. ספקו דוגמא. (5 נקודות) מהו? Monitor נא לספק הגדרה מלאה. ( נקודות) ( נקודות) ציינו כמה תהליכים יווצרו בקוד הבא כולל התהליך הראשי שאנו מניחים שזה מבצע קריאה ראשונית לפונקציה. במילים אחרות, כמה פעמים תודפס המילה fork() ספקו ניתוח מדוייק של השורות 3,4,5 בקטע הקוד. ניתן להניח שכל קריאה ל? Bla מצליחה.. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return ; 9. שאלה 2: (3 נקודות) כתבו תוכנית ב Java שבה Threads בעלי השמות,,2 כך שסדר ההרצה שלהם בתוכנית הינו: סדר זה חוזר על עצמו לנצח. תשובה שבה critical section שבו thread מדפיס בלולאה את שמו לא תתקבל. שכן סדר הרצה וסדר הדפסה זה לא אותו דבר. בשביל סדר הדפסה מספיק Thread אחד שמדפיס בלולאה את התבנית. אך זה לא מה שנדרש בשאלה. אין להשתמש ב synchronized של Java לשם סינכרון

2 שאלה 3: (3 נקודות) להלן קוד עבור זוג תהליכים. //Shared data boolean flag[2] = {false; integer next = ;// can be or //Code for process ENTRY CODE. flag[] = true; 2 while (flag[]){ 3. if (next == ){ 4. flag[] = false; 5. await(next == ); 6. flag[] = true; <CS> EXIT CODE 7.next = ; 8.flag[] =false; //Code for process ENTRY CODE. flag[] = true; 2. while (flag[]){ 3. if (next == ){ 4. flag[] = false; 5. await(next == ); 6. flag[] = true; <CS> EXIT CODE 7.next = ; 8.flag[] =false; א. ב. ג. ( נקודות) הוכיחו כי האלגוריתם לעיל מספק.mutual exclusion ( נקודות) הוכיחו כי האלגוריתם לעיל הינו.deadlock-free ( נקודות) הוכיחו כי האלגוריתם לעיל הינו.stravation-free בהצלחה! Solution sketch

3 Question - Part C: The word Bla will be printed 2 times, i.e., this code generates 2 processes in total including the main process. As Bla appears after all fork calls every process generated will print it. Prior to the answer we should recall how a sentence like <condition > && <condition 2> <condition 3> is evaluated in the C programming language (or in any language that you the students have come across so far for that matter). First, let us recall that in a sentence like <condition > && <condition 2> the second condition is evaluated only if the first condition evaluated to true. Next recall that in a sentence like <condition > <condition 2> the second condition is evaluated only if the first one was evaluated to false. Also note that && has precedence to. Now let us combine the two: <condition > && <condition 2> <condition 3> Due to operator precedence C breaks this line as (<condition > && <condition 2> ) <condition 3> Here, we have that if <condition > && <condition 2> evaluates to true then <condition 3> is not evaluated otherwise <condition 3> is evaluated. The term <condition > && <condition 2> is evaluated as we mentioned above. Recall also that fork() essentially returns two values. The parent process gets the PID of the child process while the child process gets. This will result in not all fork() calls to be invoked by each process in accordance to the rules we spoke of above. Let us now rewrite the code as follows int fork-bomb() { fork(); /* A */ (( fork() /* B */ && fork() /* C */ ) fork()); /* D */ fork(); /* E */

4 printf("bla\n"); return ; The figure on the next page illustrates all the processes that are generated thorough this code. Question 2: The solution in the exam is supposed to be in Java. Here we give pseudo-code. It is your job to translate it into Java. In your solution proper coding in Java is expected, i.e. proper usage of finally clauses and so on. Shared: int turn[3] = {,,; int coins[3] = {,,; int done[3] = {,,; Condition cond[3] = {new Condition(),new Condition(),new Condition(); Code for process i:

5 int local_cnt = ; while(true){ while(turn[i] == ) cond[i].wait(); if (coins[i] > ){ if (done[i-%3]){ print( Bla ); local_cnt += ; coins[i] -= ; if (coins[i] == ){ coins[i+ % 3] = local_cnt+; local_cnt = ; done[i] = ; done[i+%3] = ; //In each iteration we pass the turn after ONE PRINT ONLY. turn[i] = ; turn[i+ % 3] =; // GIVE UP TURN AND PASS cond[i+ % 3].signal(); Question 3: a) We start with the observation that (*)if process i is in the CS then its flag[i] = true. This is trivial if a process does not enter its inner while loop. On the other hand if it does enter then flag[i] is set to true in line of each process. Assume now towards a contradiction that the claim is false and that the algorithm does not provide mutual exclusion so that there is a point in time in which both and are in the CS. Let t_ be the time in which process reads flag[] == false in the condition of its inner while loop just before entering the CS and let t_ be the point in time in which process reads flag[] == false in the condition of its inner while loop just before entering the CS. As and both are assumed to be in the CS, it follows that t_ and t_ exist. Assume without loss of generality that t_ < t_, i.e., entered the CS before.

6 From the assumption that t_ < t_, two cases are now possible:. At time t_ process has already executed line 9 in its code and is yet to execute line 2 in its code. In which case next =, by line 8 of process s code. Hence, upon attempt to enter the CS again process will execute the inner while loop as next == it will enter the if clause and will await until next will be changed to by process which only happens when leaves the CS. Hence, and cannot be in the CS at the same time. 2. At time t_ process is in line 6 as it must be after it has set flag[] = and flag[] = true which occur in lines 5 and 7. If process is at line 6 then this is because next ==. Process awaits for next to change to which only happens when leaves the critical section. We again see that cannot be in the CS together with. b) Assume towards contradiction that both and are both found in the entry code forever. In which case both must be inside their inner while loop as the external loop consists of an assignment line and a while loop. As both are found inside their inner while loops the value of the variable is fixed and does not change forever. Assume without loss of generality that next == forever. In which case there exists a point in time in which process enters the if clause found in its inner loop set flag[] == false and waits until next changes to. As a result there exists a point in time in which process is able to pass its inner while loop and enter the CS; contradiction. c) Assume towards a contradiction that process is unable to enter the CS and is consequently stuck forever in its inner while loop. We consider the possible locations for process. As we proved that the algorithm is deadlock free only two cases are possible.. Process is in the remainder code forever. In which case flag[] == false and process will eventually pass its inner while loop. 2. Process is quicker than process - The variable next forces struct alternation between and in case both of them seek to enter the CS. More generally, the last time leave the CS it sets next =. This will cause it to block in line 6 after setting flag[] = false in line 5 which will allow process to pass its inner while loop.

Fall 2004 CS414 Prelim 1

Fall 2004 CS414 Prelim 1 Fall 2004 CS414 Prelim 1 1. The Sim City Smoking Ban problem: In the Sim-City community Woobish most people smoke, but the laws of Sim City require that non-smokers be protected from passive smoke. So

More information

מבוא למדעי המחשב תרגול 13: עצים בינאריים

מבוא למדעי המחשב תרגול 13: עצים בינאריים מבוא למדעי המחשב תרגול 13: עצים בינאריים עצים בינאריים - הגדרה הגדרה: עץ בינארי הוא עץ ריק (בלי צמתים) או עץ המורכב משורש ושני תתי-עצים, הוא עץ בינארי. ימני ושמאלי, שכל אחד מהם תרגיל 1 עץ בינארי מסודר

More information

רזח יליגרתו םי יראני ב ם

רזח יליגרתו םי יראני ב ם מבוא למדעי המחשב עצים בינאריים ותרגילי חזרה תרגול 13: עצים בינאריים - הגדרה הגדרה: עץ בינארי הוא עץ ריק )בלי צמתים( או עץ המורכב משורש ושני תתי-עצים, הוא עץ בינארי. ימני ושמאלי, שכל אחד מהם שאלה עץ בינארי

More information

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018 Lecture In the lecture on March 13 we will mainly discuss Chapter 6 (Process Scheduling). Examples will be be shown for the simulation of the Dining Philosopher problem, a solution with monitors will also

More information

Pre- and post- CS protocols. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7. Other requirements for a mutual exclusion algorithm

Pre- and post- CS protocols. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7. Other requirements for a mutual exclusion algorithm CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

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

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution 1. (15 points) A system with two dual-core processors has four processors available for scheduling. A CPU-intensive application (e.g., a program that spends most of its time on computation, not I/O or

More information

CS153: Midterm (Winter 19)

CS153: Midterm (Winter 19) CS153: Midterm (Winter 19) Name: Student ID: Answer all questions. State any assumptions clearly. Problem 1: (24 points; 5 minutes) Indicate whether each of the following statements is true or false: (T)

More information

CS4411 Intro. to Operating Systems Final Fall points 10 pages

CS4411 Intro. to Operating Systems Final Fall points 10 pages CS44 Intro. to Operating Systems Final Exam Fall 9 CS44 Intro. to Operating Systems Final Fall 9 points pages Name: Most of the following questions only require very short answers. Usually a few sentences

More information

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages CS4411 Intro. to Operating Systems Exam 1 Fall 2005 (October 6, 2005) 1 CS4411 Intro. to Operating Systems Exam 1 Fall 2005 150 points 10 pages Name: Most of the following questions only require very short

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date: 04/04/2018 Max Marks: 40 Subject & Code: Operating Systems 15CS64 Semester: VI (A & B) Name of the faculty: Mrs.Sharmila Banu.A Time: 8.30 am 10.00 am Answer any FIVE

More information

Part II Process Management Chapter 6: Process Synchronization

Part II Process Management Chapter 6: Process Synchronization Part II Process Management Chapter 6: Process Synchronization 1 Process Synchronization Why is synchronization needed? Race Conditions Critical Sections Pure Software Solutions Hardware Support Semaphores

More information

שאלה 1, סעיף ב )11 נק'(

שאלה 1, סעיף ב )11 נק'( שאלה 1, סעיף א )8 נק'( public static boolean lexlt(string s1, String s2) for (int i=0; i

More information

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008 Process Synchronization Mehdi Kargahi School of ECE University of Tehran Spring 2008 Producer-Consumer (Bounded Buffer) Producer Consumer Race Condition Producer Consumer Critical Sections Structure of

More information

CS604 - Operating System Solved Subjective Midterm Papers For Midterm Exam Preparation

CS604 - Operating System Solved Subjective Midterm Papers For Midterm Exam Preparation CS604 - Operating System Solved Subjective Midterm Papers For Midterm Exam Preparation The given code is as following; boolean flag[2]; int turn; do { flag[i]=true; turn=j; while(flag[j] && turn==j); critical

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Part III Synchronization Software and Hardware Solutions

Part III Synchronization Software and Hardware Solutions Part III Synchronization Software and Hardware Solutions Spring 2018 Computers are useless. They can only give answers. 1 Pablo Picasso Software Solutions for Two Processes Suppose we have two processes

More information

מבוא לתכנות ב- JAVA תרגול 7

מבוא לתכנות ב- JAVA תרגול 7 מבוא לתכנות ב- JAVA תרגול 7 רקורסיה - הקדמה הגדרה רקורסיבית: חדר הוא מסודר אם צד שמאל שלו מסודר שלו מסודר. וצד ימין שיטת פתרון רקורסיבית: פתרון מופעים פשוטים יותר של בעיה בכדי לפתור את הבעיה המקורית רקורסיה

More information

Process Synchronization

Process Synchronization Process Synchronization Concurrent access to shared data may result in data inconsistency Multiple threads in a single process Maintaining data consistency requires mechanisms to ensure the orderly execution

More information

CoSc 450: Programming Paradigms. The Critical Section Problem

CoSc 450: Programming Paradigms. The Critical Section Problem CoSc 450: Programming Paradigms 03 The Critical Section Problem Algorithm 3.1: Critical section problem global variables p q local variables local variables loop forever loop forever non-critical section

More information

כתבו קוד ב- 3 קבצי ה hpp (כתבו כהערה את שם הקובץ מעל) כך שהקוד יהיה תקין ובסגנון טוב. אין חובה

כתבו קוד ב- 3 קבצי ה hpp (כתבו כהערה את שם הקובץ מעל) כך שהקוד יהיה תקין ובסגנון טוב. אין חובה פקולטה: מדעי הטבע מחלקה: מדעי המחשב שם הקורס: מבנה זכרון ושפת ++C קוד הקורס: 7027810 תאריך בחינה: שאלות לדוגמא משך הבחינה: שעתיים שם המרצים: ד"ר אופיר פלא, ד"ר מירי בן ניסן חומר עזר: פתוח שימוש במחשבון:

More information

There are 10 total numbered pages, 5 Questions. You have 60 minutes. Budget your time carefully!

There are 10 total numbered pages, 5 Questions. You have 60 minutes. Budget your time carefully! UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, February, 2018 Third Year Materials ECE344H1 - Operating Systems Calculator Type: 2 Exam Type: A Examiner D. Yuan Please

More information

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems Synchronization CS 475, Spring 2018 Concurrent & Distributed Systems Review: Threads: Memory View code heap data files code heap data files stack stack stack stack m1 m1 a1 b1 m2 m2 a2 b2 m3 m3 a3 m4 m4

More information

אוניברסיטת בן-גוריון בהצלחה! מספר נבחן: מדור בחינות רשמו תשובותיכם בשאלון זה בלבד ובמקום המוקצה לכך בלבד! תשובות מחוץ לשאלון לא יבדקו.

אוניברסיטת בן-גוריון בהצלחה! מספר נבחן: מדור בחינות רשמו תשובותיכם בשאלון זה בלבד ובמקום המוקצה לכך בלבד! תשובות מחוץ לשאלון לא יבדקו. אוניברסיטת בןגוריון מדור בחינות מספר נבחן: רשמו תשובותיכם בשאלון זה בלבד ובמקום המוקצה לכך בלבד! תשובות מחוץ לשאלון לא יבדקו. תאריך הבחינה: 13.7.2008 שם המורה: ד"ר מיכאל אלחדד ניר צחר אוריאל ברגיג שם הקורס:

More information

Algorithms. Intro2CS week 5

Algorithms. Intro2CS week 5 Algorithms Intro2CS week 5 1 Computational problems A computational problem specifies an inputoutput relationship What does the input look like? What should the output be for each input? Example: Input:

More information

Mutual Exclusion. 1 Formal problem definitions. Time notion CSE /17/2015. Outline of this lecture:

Mutual Exclusion. 1 Formal problem definitions. Time notion CSE /17/2015. Outline of this lecture: CSE 539 03/17/2015 Mutual Exclusion Lecture 15 Scribe: Son Dinh Outline of this lecture: 1. Formal problem definitions 2. Solution for 2 threads 3. Solution for n threads 4. Inherent costs of mutual exclusion

More information

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year Dr. Rafiq Zakaria Campus Maulana Azad College of Arts, Science & Commerce, Aurangabad Department of Computer Science Academic Year 2015-16 MCQs on Operating System Sem.-II 1.What is operating system? a)

More information

Process/Thread Synchronization

Process/Thread Synchronization CSE325 Principles of Operating Systems Process/Thread Synchronization David Duggan dduggan@sandia.gov February 14, 2013 Reading Assignment 7 Chapter 7 Deadlocks, due 2/21 2/14/13 CSE325: Synchronization

More information

Safety and liveness for critical sections

Safety and liveness for critical sections Safety and liveness for critical sections! At most k threads are concurrently in the critical section A. Safety B. Liveness C. Both! A thread that wants to enter the critical section will eventually succeed

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need

More information

CS3331 Concurrent Computing Exam 1 Solutions Fall 2018

CS3331 Concurrent Computing Exam 1 Solutions Fall 2018 CS3331 Concurrent Computing Exam 1 Solutions Fall 2018 1 CS3331 Concurrent Computing Exam 1 Solutions Fall 2018 1. Basic Concepts (a) [10 points] Explain interrupts and traps, and provide a detailed account

More information

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions). OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions). (a) (b) (c) (d) (e) (f) (g) (h) (i) T_ The two primary purposes of an operating

More information

הנכות 1 םוכיס לוגרת 14 1

הנכות 1 םוכיס לוגרת 14 1 תוכנה 1 סיכום תרגול 14 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang Process Synchronization CISC3595, Spring 2015 Dr. Zhang 1 Concurrency OS supports multi-programming In single-processor system, processes are interleaved in time In multiple-process system, processes execution

More information

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem!

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem! 2/1/13 Today: Deadlock CSCC 69H3 Operating Systems Winter 2013 Professor Bianca Schroeder U of T Remember example from last week? My_work(id_t id) { /* id can be 0 or 1 */ flag[id] = true; /* indicate

More information

Chapters 5 and 6 Concurrency

Chapters 5 and 6 Concurrency Operating Systems: Internals and Design Principles, 6/E William Stallings Chapters 5 and 6 Concurrency Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Concurrency When several processes/threads

More information

Synchronization Spinlocks - Semaphores

Synchronization Spinlocks - Semaphores CS 4410 Operating Systems Synchronization Spinlocks - Semaphores Summer 2013 Cornell University 1 Today How can I synchronize the execution of multiple threads of the same process? Example Race condition

More information

Thread Synchronization: Too Much Milk

Thread Synchronization: Too Much Milk Thread Synchronization: Too Much Milk 1 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing mutual exclusion with memory reads and writes

More information

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems.

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems. CSE 120: Principles of Operating Systems Lecture 4 Synchronization January 23, 2006 Prof. Joe Pasquale Department of Computer Science and Engineering University of California, San Diego Before We Begin

More information

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4.

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4. CSE 120: Principles of Operating Systems Lecture 4 Synchronization October 7, 2003 Before We Begin Read Chapter 7 (Process Synchronization) Programming Assignment #1 Due Sunday, October 19, midnight Prof.

More information

Memory system behavior: volatile variables. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 6. Volatile variables and concurrency

Memory system behavior: volatile variables. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 6. Volatile variables and concurrency CS 361 Concurrent programming Dreel University Fall 2004 Lecture 6 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

Mutual Exclusion: Classical Algorithms for Locks

Mutual Exclusion: Classical Algorithms for Locks Mutual Exclusion: Classical Algorithms for Locks John Mellor-Crummey Department of Computer Science Rice University johnmc@cs.rice.edu COMP 422 Lecture 18 21 March 2006 Motivation Ensure that a block of

More information

CPS 310 first midterm exam, 2/26/2014

CPS 310 first midterm exam, 2/26/2014 CPS 310 first midterm exam, 2/26/2014 Your name please: Part 1. More fun with forks (a) What is the output generated by this program? In fact the output is not uniquely defined, i.e., it is not necessarily

More information

( B ) 4. Which is not able to solve the race condition? (A) Test and Set Lock (B) Shared memory (C) Semaphore (D) Monitor

( B ) 4. Which is not able to solve the race condition? (A) Test and Set Lock (B) Shared memory (C) Semaphore (D) Monitor CS 540 - Operating Systems - Final Exam - Name: Date: Monday, May 12, 2003 Part 1: (80 + 8 (bonus) points - 4 points for each problem) ( C ) 1. In an operating system a utility which reads commands from

More information

CSE 120: Principles of Operating Systems. Lecture 4. Synchronization. October 7, Prof. Joe Pasquale

CSE 120: Principles of Operating Systems. Lecture 4. Synchronization. October 7, Prof. Joe Pasquale CSE 120: Principles of Operating Systems Lecture 4 Synchronization October 7, 2003 Prof. Joe Pasquale Department of Computer Science and Engineering University of California, San Diego 2003 by Joseph Pasquale

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! CS 3204 Operating Systems Midterm (Abrams) Spring 2004 VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PRO SI M UNI VERSI TY Instructions: Do not start the test until instructed to do so! Print your name

More information

גיליון תשובות מספר נבחן:

גיליון תשובות מספר נבחן: גיליון תשובות מספר נבחן: 30( שאלה 1 נקודות( א. ב. התכונה הנשמרת מתייחסת אך ורק למיקום המכוניות בצומת, כלומר למיקום המכוניות בשדה _cars הגישה לשדה זה מסונכרנת, אך מצד שני אין בדיקה של מיקום המכונית טרם

More information

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Concurrency: Mutual Exclusion and Synchronization

Concurrency: Mutual Exclusion and Synchronization Concurrency: Mutual Exclusion and Synchronization 1 Needs of Processes Allocation of processor time Allocation and sharing resources Communication among processes Synchronization of multiple processes

More information

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores

More information

CSCI 447 Operating Systems Filip Jagodzinski

CSCI 447 Operating Systems Filip Jagodzinski Filip Jagodzinski Announcements Homework 2 you have 2 weeks start now Book questions including two custom ones A single programming task File names and directories, class conventions homework2-script,

More information

ב ה צ ל ח ה! אוניברסיטת בן גוריון בנגב מספר נבחן : תאריך המבחן: כ"ה תשרי תשע"ח 15/10/17 שמות המורים: ציון סיקסיק מיועד לתלמידי : א'

ב ה צ ל ח ה! אוניברסיטת בן גוריון בנגב מספר נבחן : תאריך המבחן: כה תשרי תשעח 15/10/17 שמות המורים: ציון סיקסיק מיועד לתלמידי : א' אוניברסיטת בן גוריון בנגב מספר נבחן : תאריך המבחן: כ"ה תשרי תשע"ח 15/10/17 שמות המורים: ציון סיקסיק א' ב- C תכנות מבחן ב: 202-1-9011 מס' הקורס : הנדסה מיועד לתלמידי : א' מועד קיץ סמ' שנה תשע"ז 3 שעות משך

More information

Operating Systems CMPSC 473. Synchronization February 21, Lecture 11 Instructor: Trent Jaeger

Operating Systems CMPSC 473. Synchronization February 21, Lecture 11 Instructor: Trent Jaeger Operating Systems CMPSC 473 Synchronization February 21, 2008 - Lecture 11 Instructor: Trent Jaeger Last class: CPU Scheduling Today: A little more scheduling Start synchronization Little s Law Evaluating

More information

Process Synchronization

Process Synchronization CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem

More information

Synchronisation algorithms

Synchronisation algorithms Synchronisation algorithms - Lecture Notes - Elad Aigner-Horev July 2, 2017 Contents 1. Introduction 3 1.1. Synchronisation algorithms: definition............. 4 1.2. The OS scheduler: the enemy..................

More information

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total University of Minnesota Department of Computer Science CSci 5103 - Fall 2016 (Instructor: Tripathi) Midterm Exam 1 Date: October 17, 2016 (4:00 5:15 pm) (Time: 75 minutes) Total Points 100 This exam contains

More information

Computing with Infinitely Many Processes under assumptions on concurrency and participation -M.Merritt&G.Taubenfeld. Dean Christakos & Deva Seetharam

Computing with Infinitely Many Processes under assumptions on concurrency and participation -M.Merritt&G.Taubenfeld. Dean Christakos & Deva Seetharam Computing with Infinitely Many Processes under assumptions on concurrency and participation -M.Merritt&G.Taubenfeld Dean Christakos & Deva Seetharam November 25, 2003 Abstract This paper explores four

More information

Last class: Today: CPU Scheduling. Start synchronization

Last class: Today: CPU Scheduling. Start synchronization Last class: CPU Scheduling Today: Start synchronization Synchronization Processes (threads) share resources. How do processes share resources? How do threads share resources? It is important to coordinate

More information

Chapter 7: Process Synchronization!

Chapter 7: Process Synchronization! Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors 7.1 Background Concurrent access to shared

More information

CS153: Midterm (Fall 16)

CS153: Midterm (Fall 16) Name: CS153: Midterm (Fall 16) Answer all questions. State any assumptions clearly. Problem 1: (16 points + 2 bonus; 10 minutes) Mark any 8 of the following statements as True or False. Answer all 10 to

More information

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

CS 361 Concurrent programming Drexel University Fall 2004 Lecture 8. Proof by contradiction. Proof of correctness. Proof of mutual exclusion property

CS 361 Concurrent programming Drexel University Fall 2004 Lecture 8. Proof by contradiction. Proof of correctness. Proof of mutual exclusion property CS 361 Concurrent programming Drexel University Fall 2004 Lecture 8 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

C ONTROL AND H IGHER O RDER F UNCTIONS

C ONTROL AND H IGHER O RDER F UNCTIONS Name: Date: Period: Name 2: Name 3: Name 4: 20 points C ONTROL AND H IGHER O RDER F UNCTIONS (Review questions from readings and labs) 1 Instructions: Complete all 9S CIENCE discussion C OMPUTER 61A questions.

More information

PROCESS SYNCHRONIZATION

PROCESS SYNCHRONIZATION PROCESS SYNCHRONIZATION Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization

More information

sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg

sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg sample exam Concurrent Programming tda383/dit390 Sample exam March 2016 Time:?? Place: Johanneberg Responsible Michał Pałka 0707966066 Result Available no later than?-?-2016 Aids Max 2 books and max 4

More information

Suggested Solutions (Midterm Exam October 27, 2005)

Suggested Solutions (Midterm Exam October 27, 2005) Suggested Solutions (Midterm Exam October 27, 2005) 1 Short Questions (4 points) Answer the following questions (True or False). Use exactly one sentence to describe why you choose your answer. Without

More information

Operating Systems. Sina Meraji U of T

Operating Systems. Sina Meraji U of T Operating Systems Sina Meraji U of T 1 Announcement Check discussion board for announcements A1 is posted 2 Recap: Process Creation: Unix In Unix, processes are created using fork() int fork() fork() Creates

More information

מבוא לתכנות ב- JAVA תרגול 5. Ipc161- practical session 5

מבוא לתכנות ב- JAVA תרגול 5. Ipc161- practical session 5 מבוא לתכנות ב- JAVA תרגול 5 Ipc161- practical session 5 מה בתרגול מערכים דו ממדיים )methods( פונקציות/שיטות ב- Java הגדרת פונקציה קריאה/הפעלה העברת ארגומנטים ערכי החזרה מערך דו ממדי מערך של מערכים חד ממדיים

More information

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination. Times: Thursday 2017-06-22 at 19:00 to 20:50 (7 to 8:50PM) Duration: 1 hour 50 minutes (110 minutes) Exam ID: 3520593 Please print in pen: Waterloo Student ID Number: WatIAM/Quest Login Userid: Sections:

More information

Introduction to OS Synchronization MOS 2.3

Introduction to OS Synchronization MOS 2.3 Introduction to OS Synchronization MOS 2.3 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Challenge How can we help processes synchronize with each other? E.g., how

More information

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution Race Condition Synchronization CSCI 315 Operating Systems Design Department of Computer Science A race occurs when the correctness of a program depends on one thread reaching point x in its control flow

More information

Process/Thread Synchronization

Process/Thread Synchronization CSE325 Principles of Operating Systems Process/Thread Synchronization David Duggan dduggan@sandia.gov March 1, 2011 The image cannot be displayed. Your computer may not have enough memory to open the image,

More information

Announcements. Office hours. Reading. W office hour will be not starting next week. Chapter 7 (this whole week) CMSC 412 S02 (lect 7)

Announcements. Office hours. Reading. W office hour will be not starting next week. Chapter 7 (this whole week) CMSC 412 S02 (lect 7) Office hours Announcements W office hour will be 10-11 not 11-12 starting next week Reading Chapter 7 (this whole week) 1 Problems with the Producer-Consumer Shared Memory Solution Consider the three address

More information

עמוד 1 (תאריך ( âùéä ער äìàù בכל השאלות ניתן להניח שהקלט תקין. 100 íåëñ חורף :

עמוד 1 (תאריך ( âùéä ער äìàù בכל השאלות ניתן להניח שהקלט תקין. 100 íåëñ חורף : עמוד 1 מבוא למדעי המחשב מ' 234114 מבוא למדעי המחשב ח' 234117 מבחן מועד א', סמסטר חורף תשס"ב (תאריך ( 29.1.03 שם משפחה שם פרטי מס' סטודנט âùéä ער äìàù 15 1 15 2 16 3 18 4 16 5 20 6 100 íåëñ חומר עזר: אין

More information

Synchronization: Semaphores

Synchronization: Semaphores Illinois Institute of Technology Lecture 26 4/25 solved Synchronization: Semaphores CS 536: Science of Programming, Spring 2018 A. Why Avoiding interference, while good, isn t the same as coordinating

More information

Synchronization Principles

Synchronization Principles Synchronization Principles Gordon College Stephen Brinton The Problem with Concurrency Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms

More information

Process Synchronization

Process Synchronization TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Process Synchronization [SGG7] Chapter 6 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

More information

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6. Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic

More information

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems Page 1 of 8 ITEC202 Operating Systems, Midterm Exam Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC202 Operating Systems ITEC 202 Midterm Examination

More information

Synchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait, signal, signal_broadcast. Synchronization

Synchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait, signal, signal_broadcast. Synchronization CS341: Operating System Lect20 : 16 th Sept 2014 Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Synchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait,

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 6: Algorithms for Mutual Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of this lecture mutual exclusion with standard instructions example:

More information

Lesson 6: Process Synchronization

Lesson 6: Process Synchronization Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization? Chapter 6: Process [& Thread] Synchronization CSCI [4 6] 730 Operating Systems Synchronization Part 1 : The Basics Why is synchronization needed? Synchronization Language/Definitions:» What are race conditions?»

More information

Lecture 4: Inter-Process Communication (Jan 27, 2005)

Lecture 4: Inter-Process Communication (Jan 27, 2005) Lecture 4: Inter-Process Communication (Jan 27, 2005) February 17, 2005 1 Review Q: What is the other command that seems to go hand-in-hand with fork()? A: exec* (6 variants of this command) Q: Suppose

More information

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

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 The Process Concept 2 The Process Concept Process a program in execution

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

EECE.4810/EECE.5730: Operating Systems Spring Midterm Exam March 8, Name: Section: EECE.4810 (undergraduate) EECE.

EECE.4810/EECE.5730: Operating Systems Spring Midterm Exam March 8, Name: Section: EECE.4810 (undergraduate) EECE. EECE.4810/EECE.5730: Operating Systems Spring 2017 Midterm Exam March 8, 2017 Name: Section: EECE.4810 (undergraduate) EECE.5730 (graduate) For this exam, you may use two 8.5 x 11 double-sided page of

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: 1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time: Input: A CNF formula ϕ with n variables x 1, x 2,..., x n. Output: True if there is an

More information

Thread Synchronization: Foundations. Properties. Safety properties. Edsger s perspective. Nothing bad happens

Thread Synchronization: Foundations. Properties. Safety properties. Edsger s perspective. Nothing bad happens Edsger s perspective Testing can only prove the presence of bugs Thread Synchronization: Foundations Properties Property: a predicate that is evaluated over a run of the program (a trace) every message

More information

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006 Operating Systems Comprehensive Exam Spring 2006 Student ID # 3/16/2006 You must complete all of part I (60%) You must complete two of the three sections in part II (20% each) In Part I, circle or select

More information

CS-537: Midterm Exam (Spring 2001)

CS-537: Midterm Exam (Spring 2001) CS-537: Midterm Exam (Spring 2001) Please Read All Questions Carefully! There are seven (7) total numbered pages Name: 1 Grading Page Points Total Possible Part I: Short Answers (12 5) 60 Part II: Long

More information

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators

Control and Environments Fall 2017 Discussion 1: August 30, Control. If statements. Boolean Operators CS 61A Control and Environments Fall 2017 Discussion 1: August 30, 2017 1 Control Control structures direct the flow of logic in a program. For example, conditionals (if-elif-else) allow a program to skip

More information

Find the flaw. Also show a timing diagram that indicates the sequence of actions for several interleavings.

Find the flaw. Also show a timing diagram that indicates the sequence of actions for several interleavings. ECS150 Winter 2004 Homework Assignment 3 Due: Wednesday, 10 March 2004, 4:30PM, HW box, EUII Question 1: Tanenbaum, Chapter 2-35 Question 2: Tanenbaum, Chapter 2-36 Question 3: Jurassic Park consists of

More information

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems : Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks on either

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,

More information