10 - Mutual Exclusion Flashcards

1
Q

What is mutual exclusion?

A

The problem of granting some exclusive privilege of a recourse to a process through the exchange of messages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the requirements for a mutual exclusion solution?

A
  1. Safety: exclusive access
  2. liveness: no deadlock or starvation
  3. fairness: requests granted in some time order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three classes of mutex algorithms?

A
  • election based
  • token based
  • permission based
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What class of mutex algorithm is Lamport’s?

A

Permission based

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What type of timestamps does lamport’s mutex algorithm use?

A

Every message carries a scalar logical timestamp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the major assumption for lamports mutex algorithm?

A

Channels are FIFO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In mutex algorithms, what is the abreviation CS?

A

Critical section: The data area one tries to access using mutex.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What two requirements need to be met in order for process P to own a mutex?

A
  1. It has received a reply from every process
  2. its own request is at the head of its own request queue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Decribe the pseudo code for lamports mutex alg.

A
# Requesting CS in Pi:
broadcast(REQUEST,ts,i) to all processes

Receiving request,ts,j:
send(REPLY, ts') to Pj
enter (ts,j) into the request queue

#Releasing the mutex of Pi:
send(RELEASE,i) to all processes

#Receiving a RELASE,j:
remove (ts,j) from the request queue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain Lompart’s mutex message complexity.

A

It requires (n-1) REQUESTS, REPLIES and RELEASES. So complexity of 3(n-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What improvement does Ricart’s and Agrawala’s algorithm propose? and on what algorithm?

A

Improvement on lamport’s algorithm:
If Pi receives a REQUEST for CS of PJ that is lower priority than Pi’s own request to access Pj, then it will wait with sending a REPLY untill Pi has released it.

It allows any process to access a CS as often as it likes. (capped to complexity: fi. if all other processes also request access)

It is implied here that because Pi’s request is of higher priority, it will be granted access earlier. And that by REPLYing only after mutex is released, it acts as a release of sorts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the complexity of Ricart-Agrawala’s mutex algorithm?

A

(n-1) Requests and (n-1) Replies = 2(n-1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What class of mutex algrotihm is Ricart-Agrawala’s?

A

Permission based

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What class of mutex algorithm is Maekawa’s?

A

Permission based.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the main idea of Maekawa’s mutex algorithm.

A

every process has a request set of processes to which it sends its REQUESTs and from whom it needs REPLYs (better load distribution)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the Requirements and Desirable features of the request sets in Maekawa’s mutex algorithm?

A

Requirement:
* any two request sets have a non-empty intersection

Desirable features:
* every process is in its own request set
* all request sets have the same size
* every process is contained in the same number of request sets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In Maekawa’s mutex algorithm, what is the mininum size of the request set?

A

in the order of sqrt( N )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Explain what a deadlock is, and how it can occur.

A

A deadlock is an event in the system where multiple processes are actively waiting for eachothers response, whilst no responses can be generated. This can for instance occur in asynchronous systems if mutliple requests happen simultaneously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How does Maekawa’s mutex algorithm handle deadlocks (incl. signals)?

A

Whenever process Pi has GRANTED access to Pj’s request of k, but later receives an other request for k from a different process (with higher priority), it will retract its original permission to j with an INQUIRE, which is confirmed by j with a RELINQUISH message.

However, if Pi receives a request for k that has lower priority (and it already granted k to pj), then it sends a POSTPONED

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is Meakawa’s mutex algorithm message complexity under low load?

A

if K is the request set size.
Then k-1 Requests, k-1 Grants and k-1 Release= 3(k-1)

21
Q

What is Meakawa’s mutex algorithm message complexity under heavy load?

A

if K is the request set size.
Then k-1 Requests, k-1 Grants, k-1 Releases and k-1 Postponed= 4(k-1)

22
Q

What is Meakawa’s mutex algorithm message complexity for old request?

A

if K is the request set size.
Then k-1 Requests, k-1 Grants, k-1 Replies, k-1 inquires and k-1 relinquish= 5(k-1)

23
Q

In meakawa’s algorithm, what happens after Pi receives a POSTPONED from Pj?

A

Pi will then wait untill Pj has received a RELEASE from an external process. Then Pj will send a GRANT to Pi, allowing Pi to own the mutex.

24
Q

What class of mutex alg. is the generalized mutex algorithm?

A

Permission based

25
Q

Explain the main idea of generalized mutex algorithm.

A

Every process maintains three sets:
1. request set: to which Pi requests and obtains grants
2. inform set: notify processes of requests and releases
3. status set: contains infromation about the processes to which a GRANT was sent.

26
Q

In A generalized mutex algorithm, what is the relation between the inform and status set?

A

Pj is in the inform set of Pi iff Pi is in the status set of Pj

27
Q

In the generalized mutex algorithm, what is the relation between the information set and the request sst?

A

The information set is a subset of the request set.

28
Q

In generalized mutex algorithm, when are two processes regarded related?

A

Either they are in eachother’s request sets (Ricart-agrawala), or the intersection of the inform set is not empty (meakawa)

29
Q

In the generalized mutex algorithm, what is the condition for Pi to enter a CS?

A

If it has received a GRANT from all pocesses in Ri (request set)

30
Q

For generalized mutex algorithm, explain the psuedo code for Releasing. (send and receive)

A

Releasing the CS in Pi:
~~~
send(RELEASE) to processes in information set.
~~~

Receiving a release:
~~~
CSSTAT = NULL
until request_queue == empty or CSSTAT != NULL:
Pj = popped head of request queue
send(GRANT) to Pj
if Pj in Si: (status set)
CSSTAT = j
~~~

31
Q

For generalized mutex algorithm, explain the psuedo code for Requesting. (send and receive)

A

Requesting the CS in Pi:
~~~
send(REQUEST) to all processes in request set.
~~~

Receiving a request from Pj:
~~~
if CSSTAT == NULL:
send(GRANT) to Pj
if Pj in Si: (status set)
CSSTAT = j
else:
enter(ts,j) into request queue
~~~

32
Q

Explain how the request, informatoin and status set are constructed to produce Ricarts-Agrawala algorithm from the generalized mutex alg.

A

Ri = {0, 1, … , n-1} (all process send request to all processes)
Ii = {i} (processes do not send releases)
Si = {i} (processes only keep track of own status)

33
Q

Explain how the request, informatoin and status set are constructed to produce Maekawa’s algorithm from the generalized mutex alg.

A

Ri = set[k] (request set is subset of size k inlcuding i)
Ii = Ri (send releases to processes in your request set)
Si = {i} (processes keep track of own status)

34
Q

What class is Suzuki-Kasami’s mutex algorithm?

A

Token based

35
Q

Explain how Suzuki-Kasami’s mutex algorithm works. What data structuresa are needed?

A

A process can exclusively access an CS when it has hold of the token.
Every process maintains an array N, that tracks the last request of each process. When a process wants access to the token, it broadcasts an value that is updated in N by every process.
The token also contains such an array, TN, that maintains the values of all the processes since its last visit to them. Whenever it leaves a process, it’s value of that process is updated.

36
Q

Explain how the order of the token is decided in Suzuki-Kasami’s mutex algorithm, and wheter this is fair.

A

When a process wants to release the token, it evaluates for which next process it satisfies N[i] > TN[i]. (Meaning that Process Pj has received an request by Pi and the token has not been there yet)

If there is no difference between N and TN, the token stays put untill request arrives.

This is fair because the evaluation starts at Process ID. All processes will get access in due time.

37
Q

Explain the variation of Suzuki-Kasami’s mutex algorithm.

A

The token also maintains queue Q, that holds all the processes that have an active request for that token. Q is updated when the token leaves a process. (and the token is send to the head of Q).

38
Q

What is the message complexity of Suzuki-Kasami’s mutex algorithm?

A

n-1 token requests + 1 token transfer = n messages

39
Q

What is the main idea behind singhal’s mutex algorithm?

A

If the processes and token keep track of the status of each process (e.g. if they have requested the token). Then a process’ own token request only has to be send to processes who might have the token. This reduces message complexity even more.

40
Q

What is the initial values for the state array for Singhal’s mutex algorithm?

A

P 1: H O O O … O O
P 2: R O O O … O O
P 3: R R O O … O O

P N: R R R R … R O

H: holds, R: requests, O: other - the token

41
Q

Explain the psuedo code for receiving a request in Singhal’s mutex alg. (for each state)

A

Upon receiving request;j,r

N[j] = r
case S[i]:
   E or O: S[j] = R
	 R: if S[j] != R:
	         S[j] = R
					 send(request,i,N[i]) to Pj  # Pj did not receive update before
		H: S[i] = R; S[i] = O
		     TS[j] = R; TN[j] = r
				 send(token) to Pj

r is the request count of process j

42
Q

Explain the psuedo code for receiving a token in Singhal’s mutex alg. (for each state)

A

Upon receiving request;j,r

S[i] = E
Critical Section
S[i] = O; TS[i] = O
for j in range(n):
if N[j] > TN[j] then:
    TN[j] = N[j] ; TS[j] = S[j]
else:
    N[j] = TN[j] ; T[j] = TS[j]

if S[j] for all j in n:
    S[i] = H
else:
    send(token) to Pj
    

r is the request count of process j

43
Q

What is the message complexity of Singhal’s mutex algorithm (low contention)?

A

on average, n/2 messages per CS

44
Q

What is the message complexity of Singhal’s mutex algorithm (high contention)?

A

on average, n messages per CS

45
Q

Explain the main idea of Raymonds algorithm.

A

It operates on a binary spanning tree. By default the root holds the token. A request can be made through the spanning tree to obtain the token. When a (intermediate) node gets the token, it becomes the new root. A node only forwards a request using its own ID (only tree neighbours are known). If a node receives multiple requests (f.i. from both childs), it puts them in the request_queue. Then when it has sent a token to one child, it also requests it back in order to send it to the other child.

46
Q

Explain why, in Raymonds mutex algorithm, token requests are always send upwards?

A

A node only knows its own ID and it’s parents. Furthermore, the root changes with the holder of the token. Hence, when you want the token you can request your parent. The parent either holds the token (and therefor is root) or he can request his parent (etc.)

47
Q

What is the message complexity for raymonds mutex algorithm in worst case low contention?

A

2(D-1) with D the diamter of the tree.
D = N for linear tree
D= log N for random trees

Diameter of tree is longest path between any two nodes.

48
Q

What is the message complexity for raymonds mutex algorithm in high contention?

A

In high contention, a node always requests its token back. Meaning a request and token transfer in both ways = 4 messages on average