1) Threads and processes are both sets of instructions that are being executed. The main difference between the two is that a process can be made up of several different threads which can be run concurrently.

 

2) Possible values are 0, 1 and 2.

 

Example which produces x = 0:

T1 Load

T1 Decrease

T1 Store

T2 Load

T2 Decrease

T2 Store

T3 Load

T3 Decrease

T3 Store

 

Example which produces x=1:

T1 Load

T1 Decrease

T1 Store

T2 Load

T3 Load

T2 Decrease

T2 Store

T3 Decrease

T3 Store

 

Example which produces x=2

T1 Load

T2 Load

T3 Load

T1 Decrease

T1 Store

T2 Decrease

T2 Store

T3 Decrease

T3 Store

 

3) Yes, it does severely and unnecessarily degrade the progress of P2 which has to wait for P1 to finish its long non-critical section in order to run if it runs twice before P1 finishes. P1 is unlikely to finish the CS and the non-CS while P2 is in its non-CS and so should not be forced to wait for longer than the CS of P2.

 

4) It is possible that they could deadlock if they both enter at the same time. Imagine if they both enter, set both flags to true and then both get stuck on the while loop. However if only 1 flag is initialized to true, they can not both be in the critical section.

 

5) They could both be in the critical section at the same time if they both enter at the same time. Imagine that they both enter, pass the while loop together, set both flags to true and then both enter the critical section. However, they canít deadlock as that would require both to be stuck in the while loop with both flags true and they can not both reach the while loop with both flags true.

 

6i) The producer produces 2 items so it calls append() twice. IN goes from 0 to 1 to 0 again. The consumer takes 1 item so take() is called and OUTgoes from 0 to 1. The producer is unblocked and calls append() and IN goes to 1.

 

6ii) S = 1. N = 0. E = 2. The producer produces 2 items so E goes from 2 to 1 to 0. S goes to 0 and back to 1 before and after append(). N is signaled twice so it goes from 0 to 1 to 2. The consumer consumes one item so N goes from 2 to 1 and S goes from 1 to 0 to 1 around take(). E is signaled once so it goes from 0 to 1. The producer is called one final time so E goes from 1 to 0, S goes from 1 to 0 to 1 and N goes from 1 to 2.

 

7i) No because the producer could attempt to access a full buffer, get past the wait(S) and be blocked at wait(E). Now the consumer get past the wait(S) to consume an item and it is blocked too. Deadlock occurs.

 

7ii) See above answer, only this time deadlock occurs when the consumer attempts to access an empty buffer.

 

7iii) Yes, as there is no possible way for the producer to get struck and fail to signal both S and N. No change occurs.

 

7iv) Yes, as there is no possible way for the consumer to get struck and fail to signal both S and E. No change occurs.

 

8) The total number of sectors on the floppy drive has increased by a factor of 4 from 2880 to 11520. We now need a total of (11520-FAT table) entries to cover the whole disk. The number of bits in each entry now needs to be 14 bits as 2^14 = 16384. We can only fit 146 entries per sector now so we need a total of 79 sectors to cover all of the sectors. Actually, by the time we factor in the back up of the FAT table and the root directory, we only need 78 sectors to cover all of the data sectors.