You are on page 1of 3

Operating System (Chapter 6)

1. List four design issues for which the concept of concurrency is relevant
a. Communication among process
b. Sharing of and competing for resources
c. Synchronization of the activities of multiple processes
d. Allocation of processor time to processes

2. What is a “race condition”?


a. Occurs when multiple processes or threads read and write shared data items in ways
that the final outcome depends on the order of execution of instructions
b. Suppose there are n number of processes that share a global variable c that is initialized
to 1
c. At some point in the execution
i. A process, say Pi, updates c = 2
ii. Another process Pj increments c by 1
iii. Another process Pk updates c = 5
d. The final value of c will depend on the order in which these processes execute their
tasks
e. If the order is <Pi, Pj, Pk> then the value of c will be 5 and updates by Pi and Pj will be
lost
f. And if the order is <Pk, Pi, Pj>, then the value of c will be 3, and the update by Pk will be
lost. The update by Pj depends on the previous update by Pi

3. List three degrees of awareness between processes and briefly define each
a. Processes unaware of each other
i. These are independent processes that are not intended to work together
b. Processes indirectly aware of each other
i. These are processes that are not necessarily aware of each other by their
respective process IDs, but that share access to some object, such as an I/O
buffer
c. Process directly aware of each other
i. These are processes that are able to communicate with each other by process ID
and which are designed to work jointly on some activity

4. What is the distinction between competing processes and cooperating processes?


a. Competing:
i. Processes unaware of each other
ii. Results of one process independent of the action of others
iii. Compete for resources. For example, two independent applications may both
want to access the same disk or file or printer. The OS must regulate these
accesses.
b. Cooperating
i. Processes indirectly aware of each other
ii. Processes directly aware of each other
iii. Results of one process may depend on information obtained from others
iv. Either share access to a common object, such as memory buffer OR are able to
communicate with each other and cooperate in the performance of some
application or activity. For example, a producer and a consumer process sharing
a common buffer

5. List the THREE control problems associated with competing processes and briefly define each
a. Mutual exclusion – competing processes can only access a resource that both wish to
access one at a time; mutual exclusion mechanisms must enforce
this one at a time policy
b. Deadlock – if competing processes need exclusive access to more than one resource
then deadlock can occur if each processes gained control of one resource
and is waiting for the other resource.
c. Starvation – one of a set of competing processes may be indefinitely denied access to a
needed resource because other members of the set are monopolizing that
resource.

6. What is starvation with respect to concurrency control by mutual exclusion?


a. If it is mutually exclusive, it means one process can only enter its critical section at one
time
b. Starvation occurs when many processes are contending to enter in the critical section
and a process is indefinitely denied access
i. Although this process is ready to execute in its critical section, it is never chosen,
and it is never chosen and it is never able to complete

7. What operations can be performed on a semaphore?


a. A semaphore may be initialized to a nonnegative integer value
i. Binary semaphore init to 1
ii. Counting semaphore init to > 1 (depends on num of rss)
b. Wait () decrements the semaphore value
i. Then if the value becomes negative, then the process executing the Wait is
blocked
ii. Otherwise, the process continues execution
c. Signal () increments the semaphore value
i. If the resulting value is more than or equal to zero, then a process blocked by a
Wait operation is unblocked
d. RECALL: Lecture slides version = busy waiting
i. If semaphore <= 0, busy wait (infinite loop)
ii. Constantly checks if semaphore <= 0
e. A different implementation of semaphore (with busy wait)

Wait (s) { signal (s) {


While (S <= 0) ; // no – op S++;
S -- ; }
}
f. A different implementation of semaphore (no busy wait)

P (Semaphore S) { V (Semaphore S) {
S = s – 1; S = s + 1;
If (s < 0) { If (s >= 0) {
// add process to queue // remove process p from queue
block (); wakeup(p);
} }
} }

8. What is the difference between binary and general semaphore?


a. Both semaphores still use the wait and signal operation
i. Wait() to claim resource (decrease semaphore)
ii. Signal() to release resource (increase semaphore)
b. A binary semaphore
i. Values 0 and 1
c. A general semaphore (example counting semaphore)
i. May take on any integer value
ii. Initialized to number of resources available

9. What is the key difference between mutex and binary semaphore?


a. A mutex is a mutual exclusion object that is created so that multiple processes can take
turns in accessing a shared variable or resource
i. The process that locks a mutex must also unlock it
b. A binary semaphore is a synchronization variable used for signaling among processes; it
can take on only two values: 0 and 1
i. If wait() is executed by one process, the signal() can be executed by either that
process or by any another process
c. Mutex
i. To gain exclusive access to resource
ii. A producer/ consumer can gain the mutex to access the buffer
iii. If writing to buffer, don’t read…. vice versa
d. Binary Semaphore
i. For task synchronization (eg enforcing sequence… only consume if there is data)
ii. If a consumer tries to access when no data (S = 0) then it busy waits
iii. When producer creates data, it will signal (S++)
iv. Semaphore becomes 1, so the consumer can now proceed

10. What conditions are generally associated with the readers/ writers problems?
a. Any number of readers may simultaneously read the file
b. Only one writer at a time may write to the file
c. If a writer is writing to the file, no reader may read it and vice versa

You might also like