Quiz 2 with Solution on System Programming | CS 241, Quizzes of Computer Science

Material Type: Quiz; Professor: Gupta; Class: System Programming; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Spring 2006;

Typology: Quizzes

Pre 2010

Uploaded on 03/10/2009

koofers-user-vor
koofers-user-vor 🇺🇸

8 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Quiz 2
Course: cs241 - System Programming, CS Department
Date: February 10, 2006
Netid: Name:
Note: Completion of quiz is an individual effort. The quiz takes 10 minutes. The student
gets additional 5 points for taking the quiz. Each question has ONLY ONE ANSWER!!!
------------------------------------------------------------------------------------------------------------
1. (1 Point) Threads of the same task have the following characteristics: (I) Share
the same address space, (II) Reduce context switching overhead; (III) Are
protected from each other the same way as processes. Which thread
characteristics are correct?
a. I, II, III
b. I, III
c. I, II
2. (1 Point) If a user process P runs two user-threads, T1(read-thread), and T2
(compute-thread) on top of a multi-threaded kernel, and thread T1 calls ‘read’
instruction, the following happens:
a. user process P will block and another process Q will run
b. thread T1 will block and T2 will run
c. kernel threads will block
Note: Since the binding between user threads and OS threads of the multi-threads
kernel was ambiguous (i.e., both threads of the process P could be bound to one or
two OS threads), we accepted answer (a) as well as a correct anwer.
3. (1 Point) Priority inversion between two processes, one with high priority and
the other with low priority, that share a critical section, will cause the following
problem:
a. high priority process executes before low priority process and finishes
faster than it should
b. low priority process executes before high priority process and finishes
faster than it should
c. high priority process waits for low priority process (that holds the
semaphore) to finish, but the low priority process never gets
scheduled
d. low priority process changes priority temporary to the priority of the high
priority process
4. (1 Point) What is the minimum number of parameters to a ‘message send
operation?
a. 1
b. 2
c. 3
pf3
pf4

Partial preview of the text

Download Quiz 2 with Solution on System Programming | CS 241 and more Quizzes Computer Science in PDF only on Docsity!

Quiz 2

Course: cs241 - System Programming, CS Department

Date: February 10, 2006

Netid: Name:

Note: Completion of quiz is an individual effort. The quiz takes 10 minutes. The student gets additional 5 points for taking the quiz. Each question has ONLY ONE ANSWER!!!


1. (1 Point) Threads of the same task have the following characteristics: (I) Share the same address space, (II) Reduce context switching overhead; (III) Are protected from each other the same way as processes. Which thread characteristics are correct? a. I, II, III b. I, III **c. I, II

  1. (1 Point) If a user process P runs two user-threads, T1(read-thread), and T** (compute-thread) on top of a multi-threaded kernel, and thread T1 calls ‘read’ instruction, the following happens: a. user process P will block and another process Q will run b. thread T1 will block and T2 will run c. kernel threads will block

Note: Since the binding between user threads and OS threads of the multi-threads kernel was ambiguous (i.e., both threads of the process P could be bound to one or two OS threads), we accepted answer (a) as well as a correct anwer.

3. (1 Point) Priority inversion between two processes, one with high priority and the other with low priority, that share a critical section, will cause the following problem : a. high priority process executes before low priority process and finishes faster than it should b. low priority process executes before high priority process and finishes faster than it should c. high priority process waits for low priority process (that holds the semaphore) to finish, but the low priority process never gets scheduled d. low priority process changes priority temporary to the priority of the high priority process 4. (1 Point) What is the minimum number of parameters to a ‘ message send operation? a. 1 b. 2 c. 3

5. (1 Point) Rendezvous message passing synchronization approach requires a. Double buffering b. No buffering c. A buffer queue d. A place to meet 6. (1 Point) Consider the 2-process solution to the critical section problem ( ‘i’ refers to the current process and ‘j’ is the other one):

repeat while turn <> i do no-op; turn:=j; until false;

This solution does NOT satisfy a. Mutual Exclusion b. Progress c. Bounded Waiting d. Both (b) and (c) e. None of the above

Note: This is the strict alteration solution from Tanenbaum book, chapter 2.2. Bounded waiting is inherently satisfied in strict alteration solution because the code forces each process to be only once in critical region, and after that another process must access the critical region. Hence, each process waits only one cycle to get in the critical region. What is NOT satisfied is progress since one process could block in remainder section and the progress of the overall solution would be hindered. See Tanenbaum textbook and also class notes.

9. (2 Points) Complete the pseudo-code solution to the bounded buffer problem, assuming names Down()=P(), Up()=V() , and given:

binary semaphore m; semaphore f; /* counting semaphore/ semaphore d; / counting semaphore*/ m=1; f=n; d=0;

Producer(i): Loop: …………………/* (1) …………………/* (2) Deposit new data x into buffer V(m); …………………/* (3) EndLoop

Consumer(i): Loop: P(d); P(m); Consume next data y from buffer ………………/* (4) ………………/* (5) EndLoop

a. P(f)=>(1), P(m)=>(2), V(f)=>(3), V(m)=>(4), V(d)=>(5) b. P(f)=>(1), P(m)=>(2), V(d)=>(3), V(m)=>(4), V(f)=>(5) c. P(d)=>(1), P(m)=>(2), V(d)=>(3), V(m)=>(4), V(d)=>(5) d. P(d)=>(1), P(m)=>(2), V(f)=>(3), V(m)=>(4), V(d)=>(5)

Note: This is the producer/consumer problem with bounded buffer solved with counting semaphores (using m for mutex, f for empty and d for full semaphores in the Tanenbaum book, chapter 2.2) – see lecture notes, Tanenbaum textbook and R&R implementation