Assignment-2 (TCS/TIT 503)

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

1. Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Chapter 5 Asynchronous Concurrent Execution

MS Windows Concurrency Mechanisms Prepared By SUFIAN MUSSQAA AL-MAJMAIE

CSE 153 Design of Operating Systems

Homework #3. CS 318/418/618, Fall Handout: 10/09/2017

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

10/17/2011. Cooperating Processes. Synchronization 1. Example: Producer Consumer (3) Example

Part II Process Management Chapter 6: Process Synchronization

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

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

Interprocess Communication By: Kaushik Vaghani

Symmetric Multiprocessors: Synchronization and Sequential Consistency

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Remaining Contemplation Questions

CS 153 Design of Operating Systems Winter 2016

Concurrency: Mutual Exclusion and Synchronization. Concurrency

CSE 153 Design of Operating Systems

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Synchronization I. Jo, Heeseung

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

Introduction to OS Synchronization MOS 2.3

Chapters 5 and 6 Concurrency

Mutual Exclusion and Synchronization

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

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

CS420: Operating Systems. Process Synchronization

Chapter 6: Process Synchronization

Implementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

CS370 Operating Systems

Chapter 6: Process Synchronization

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

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

Concurrency. Chapter 5

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

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

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

a. A binary semaphore takes on numerical values 0 and 1 only. b. An atomic operation is a machine instruction or a sequence of instructions

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

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

Concurrency: Mutual Exclusion and

Midterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9

Homework #3. CS 318/418/618, Fall Ryan Huang Handout: 10/01/2018

Operating Systems. Synchronization

CS 318 Principles of Operating Systems

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

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

CS350: Final Exam Review

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

PESIT Bangalore South Campus

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

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

Concurrency: Mutual Exclusion and Synchronization

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

CS-537: Midterm Exam (Spring 2001)

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

Resource management. Real-Time Systems. Resource management. Resource management

Concurrency: State Models & Design Patterns

IT 540 Operating Systems ECE519 Advanced Operating Systems

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

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

Process Synchronization

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Concurrency: Mutual Exclusion (Locks)

Process Synchronization

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

Synchronization Spinlocks - Semaphores

Synchronization for Concurrent Tasks

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

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

CS3733: Operating Systems

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

Lecture 5: Synchronization w/locks

SPIN, PETERSON AND BAKERY LOCKS

Dept. of CSE, York Univ. 1

Operating Systems. Synchronisation Part I


Lecture 2: Intro to Concurrent Processing

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

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

* What are the different states for a task in an OS?

Spring CS 170 Exercise Set 1 (Updated with Part III)

Final Exam Preparation Questions

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

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

COMP SCI 3SH3: Operating System Concepts (Term 2 Winter 2006) Test 2 February 27, 2006; Time: 50 Minutes ;. Questions Instructor: Dr.

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

1995 Paper 10 Question 7

CS533 Concepts of Operating Systems. Jonathan Walpole

Process Synchronization

High Performance Computing Course Notes Shared Memory Parallel Programming

GATE SOLVED PAPER - CS

SNS COLLEGE OF ENGINEERING

Concurrency: a crash course

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

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.

Transcription:

Assignment-2 (TCS/TIT 503) Topics covered: Threads, Process Synchronisation, Semaphores Submission dates: 1)CS A:Monday,26/10/2015 (Time: between 12 pm to 1 pm) 2)CS B:Monday,26/10/2015(in the lecture of OS) 3)IT:Monday,26/10/2015 (Time: between 12 pm to 1 pm in the cabin of Mr. Dilip kumar) The assignments will not be submitted after the due timings on the same day also(applicable for all sections). Q1) Can a multithreaded solution using multiple user-level threads achieves better performance on a multiprocessor system than on a single-processor system? Q2) What can be the circumstances under which a multithreaded solution using multiple kernel threads provide better performance than a single-threaded solution on a singleprocessor system? Q3) A web server is implemented using the following 2 approaches. Approach 1: For each connection request, create a new separate process to handle that request. Approach 2: A single process is running on server to listen the incoming request and then for each connection request, a new thread is created. The web server has 1 GB memory space in total. Each process which is created on server takes 10 MB of memory space. Each thread takes 100 KB of memory space. a) Find the maximum number of connections which can be created in approach 1 and approach 2, assuming no memory space is taken by OS on server. b) Repeat the part (a), assuming 2 MB of memory space is taken by OS on server. c) Which of the approach: approach 1 or approach 2 seems to be better and why?

Q4) The following is a set of three interacting processes that can access two shared semaphores: semaphore U = 3; semaphore V = 0; [Process 1] [Process 2] [Process 3] L1:wait(U) L2:wait(V) L3:wait(V) printf("c") printf("a") printf("d") signal(v) printf("b") goto L3 goto L1 signal(v) goto L2 Within each process the statements are executed sequentially, but statements from different processes can be interleaved in any order that is consistent with the constraints imposed by the semaphores. When answering the questions below assume that once execution begins, the processes will be allowed to run until all 3 processes are stuck in a wait() statement, at which point execution is halted. a) Assuming execution is eventually halted, how many C's are printed when the set of processes runs? b) Assuming execution is eventually halted, how many D's are printed when this set of processes runs? c) What is the smallest number of A's that might be printed when this set of processes runs? d) Is CABABDDCABCABD a possible output sequence when this set of processes runs? e) Is CABACDBCABDD a possible output sequence when this set of processes runs? f) Is it possible for execution to be halted with either U or V having a non-zero value? Q5) The following pair of processes share a common variable X: Process A Process B int Y; int Z; A1: Y = X*2; B1: Z = X+1; A2: X = Y; B2: X = Z; X is set to 5 before either process begins execution. As usual, statements within a process are executed sequentially, but statements in process A may execute in any order with respect to statements in process B. A. How many different values of X are possible after both processes finish executing?

B. Suppose the programs are modified as follows to use a shared binary semaphore S: Process A Process B int Y; int Z; wait(s); wait(s); A1: Y = X*2; B1: Z = X+1; A2: X = Y; B2: X = Z; signal(s); signal(s); S is set to 1 before either process begins execution and, as before, X is set to 5. Now, how many different values of X are possible after both processes finish executing? C. Finally, suppose the programs are modified as follows to use a shared binary semaphore T: Process A Process B int Y; int Z; A1: Y = X*2; B1: wait(t); A2: X = Y; B2: Z = X+1; signal(t); X = Z; T is set to 0 before either process begins execution and, as before, X is set to 5. Now, how many different values of X are possible after both processes finish executing? Q6) The following pair of processes share a common set of variables: "counter", "tempa" and "tempb": Process A Process B...... A1: tempa = counter + 1; B1: tempb = counter + 2; A2: counter = tempa; B2: counter = tempb;...... The variable "counter" initially has the value 10 before either process begins to execute. A. What different values of "counter" are possible when both processes have finished executing? Give an order of execution of statements from processes A and B that would yield each of the values you give. For example, execution order A1, A2, B1, B2 would yield the value 13.

B. Modify the above programs for processes A and B by adding appropriate signal and wait operations on the binary semaphore "sync" such that the only possible final value of "counter" is 13. Indicate what should be the initial value of the s emaphore "sync". D. Modify the original programs for processes A and B by adding binary semaphores and signal and wait operations to guarantee that the final result of executing the two processes will be counter = 11. Give the initial values for every semaphore you introduce. Q7) Write the producer-consumer solution using monitors with the explanation. Q8) Both busy waiting and blocking methods can be used as means to address critical section problems and process synchronization. Describe how blocking is different from busy waiting, and discuss the advantages and disadvantages of each. Q9) Do semaphores solve the problem of process synchronization completely? What are some of the things that might still go wrong in a solution that requires synchronization using semaphore? Q10) Consider the following program fragment: semaphore s1=1,s2=1; wait(s1); a++; wait(s2); v++; wait(s2); wait(s1); (s1, s2 are counting semaphores). Now, consider two processes(or threads ) running this fragment of code simultaneously, can there be a deadlock? Why, or why not? Q11) Consider the following code: shared int flag[2]=0,0, turn=0; Process 1: Process 2: flag[0]=1; turn=1; while(flag[1]==1&&turn==0) ; critical section; flag[0]=0; flag[1]=1; turn=1; while(flag[0]==1&&turn==1) ; critical section; flag[1]=0;

check the following code and tell which of the 3 requirements (Mutual exclusion, bounded waiting, progress) is violated. Q12) Answer the following semaphore regarding counting semaphore. Give brief explanation for each. a)can there ever be a process blocked one semaphore with non negative value? b)can a semaphore have negative value without having any process blocked on it? Q13) Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes Process X: Process Y: / *other codefor process X * / while (true) P= true; Q= true; while (Q== true) / *criticalsection*/ P=false; / *other codefor process X*/ / *other codefor process Y * / while (true) Q= true; P= true; while (P== true) / *criticalsection*/ Q=false; / *other codefor process Y*/ Here, P and Q are shared variables and both are initialized to false. Which one of the following statements is true? (A) The proposed solution prevents deadlock but fails to guarantee mutual exclusion (B) The proposed solution guarantees mutual exclusion but fails to prevent deadlock (C) The proposed solution guarantees mutual exclusion and prevents deadlock (D) The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion Give proper explanation for your answer.

Q14) The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0=1, S1=0, S2=0. Process P0 Process P1 Process P2 while (true) wait (S0); print (0); release (S1); release (S2); wait (S1); Release (S0); wait (S2); release (S0); How many times will process P0 print '0'? (a) At least twice (b) Exactly twice (c) Exactly thrice (d) Exactly once Give proper explanation for your answer. Q15) Consider a multiprocessor system and a multithreaded program written using the many-to-many threading model. Let the number of user-level threads in the program be more than the number of processors in the system. Discuss what will happen performance wise in the following scenarios. a. The number of kernel threads allocated to the program is less than the number of processors. b. The number of kernel threads allocated to the program is equal to the number of processors. c. The number of kernel threads allocated to the program is greater than the number of processors but less than the number of user level threads. Q16) A single-lane bridge connects the two villages,village A and Village B. Farmers in the two villages use this bridge to deliver their produce to the neighbouring town. The bridge can become deadlocked if both a northbound and a southbound farmer get on the bridge at the same time (Both village farmers are stubborn and are unable to back up). Using exactly one semaphore, design an algorithm that prevents deadlock. Do not be concerned about starvation and inefficiency. Q17) If the wait() and signal() semaphore operations are not executed atomically, then can mutual exclusion be violated? Why or why not?