Written Assignment 10

Question 1

similarities

differences

child processes (process)

multi-threaded program (thread)

Question 2

Answer: There are two critical sections.

Justify: Because count1 and count2 is shared, and their operations are not atomic (can be break down into load and store instructions), it is possible for two load instructions to interleave to produce the following patterns:

Thread 1: load count1 == 0
Thread 2: load count1 == 0
Thread 1: store count1 = count1 + 1 = 1
Thread 2: store count1 = count1 + 1 = 1

Therefore, when count1 == 2 is expected, we will observe that count1 == 1 holds. (count2 follows in the same logic)

Synchronize: there are following methods

  1. avoid sharing of global variables
  2. use synchronization libraries like mutex or semaphores to synchronize code by surrounding count1++ and count2++ with chosen lock and unlock functions.
  3. don't use multiple threads

Question 3

This is a livelock. Observe that the pot is actually being passed around and therefore apparent progress is made to serve both Abi K and Rashmi (therefore not a deadlock). However, no actual progress is made (therefore not a starvation) since neither of two people are getting their requested stew.

Table of Content