Concurrency Flashcards

(25 cards)

1
Q

What is an atomic instruction

A

is an instruction, when executed doesn’t get interleaved with another process

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

what is a critical section

A

it’s a piece of code that tries to be executed by several processes

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

what is mutual exclusion

A

the execution of the critical section must never be interleaved

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

what is deadlock

A

happen when a process waits for another indefinitly

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

what is starvation

A

can be defined such that when a process wishing to enter its critical section, doesn’t have to wait indefinitely

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

livelock

A

when processes are constantly changing but none of them can proceed

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

cite the five states of a process

A

inactive –> ready running –>completed
^ |
|___ _ __ __ |—> blocked

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

Semaphores

A

S : { V : integer , L : set of processes }

initialized S –> (K, ∅)

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

Which unrealistic assumption is required for the correctness of the Ricart-Agrawala algorithm

A

it’s illogical to assume that all nodes would always answer

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

what is the idea behind the bakery algorithm?

A

the idea is to give processes tickets with increasing number, and the waiting process having the smallest ticket number is server first

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

explain the bakery algorithm for n process

A
each process would pick the max  ticket number that is exactly greater than the max 
loop forever
p1: non-critical section
p2: number[i] ← 1 + max(number)
p3: for all other processes j
p4: await (number[j] = 0) or (number[i] ≪ number[j])
p5: critical section
p6: number[i] ← 0
each time the process with the lowest  ticket number is chosen in case of conflict, we choose the lowest identifier 
however, this algorithm is unrealistic because it making the assumption that the max number is an atomic operation the following fixes that 
loop forever
p1: non-critical section
p2: choosing[i] ← true
p3: number[i] ← 1 + max(number)
p4: choosing[i] ← false
p5: for all other processes j
p6: await choosing[j] = false
p7: await (number[j] = 0) or (number[i] ≪ number[j])
p8: critical section
p9: number[i] ← 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is a blocked process?

A

it is a process that is not eligible to run

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

explain semaphores

A

semaphore is composed of two :
s.v -> unsigned integer
s.L -> list of processes
wait(s) decrement, else the process, else the process is added to the waiting list
signal(s) increment and the process may resume the execution

▶ wait(S)
if S.V > 0
S.V ← S.V - 1
else
S.L ← S.L + p
p.state ← blocked
▶ signal(S)
if S.L = ∅
S.V ← S.V + 1
else
let q be an arbitrary element of S.L
S.L ← S.L \ {q}
q.state ← ready
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

explain what is the flaw of the semaphore and how to fix it

A

in the previous definition, semaphore may lead to starvation because each time the processes are chosen arbitrarily, this can be fixed by setting up a FIFO to put the processes in

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

what is a synchronization problem?

A

it s the problem that arises when several processes compete for shared resource

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

explain how to solve the merge sort problem using synchronization

A
sorting the fist half and the second half is independent however the emerging must wait that they finish : 
Array a 
binary semaphore S1 ← (0, ∅)
binary semaphore S2 ← (0, ∅)
sort1 
sort first A.half1
signal(S1)
sort2 
sort  A.half2  
signal(S2)
merge : 
wait(S1)
wait(S2)
merge(A.half1, A.half2)
17
Q

implement producer, consumer using the semaphores

A
producer: 
loop : 
  d -> produce
  append(d, buffer)
 signal(not_empty)

consumer :
loop
wait(not_empty)
consume(buffer)

18
Q

implement producer-consumer with semaphores for a finite buffer

A
Since  buffers are finite, then we must ensure  not to write  to a full buffer
producer: 
loop : 
  d -> produce
wait(not_full)
  append(d, buffer)
 signal(not_empty)
consumer : 
loop
wait(not_empty)
 consume(buffer)
signal(not_ful;)
19
Q

why in the Ricart-Agrawala algorithm, tickets number can not be compared

A

it is an algorithm for mutual exclusion in a distributes system
because there is no shared memory between them
another point to consider is the fact that the process should only die out of it critical section

20
Q

explain Ricart-agrawala algorithm

A

Initially,
1-the highest number process is chosen
2 -a request is sent by this process, to all the node to get permission to enter the critical section
3- in the receiving the priority is compared then decides whether to send the request or add the process to the deferred list

21
Q

what are the desirable properties of the distributes system

A

fault tolerance . one failure wont affect the whole system

fail-safety : failing won’t cause damage to the whole system

22
Q

explain the consensus problem

A

There are duplicate CPUs and sponsors and values are filtered by a comparator
initially, each node picks a value and sends it to the others, then through the majority vote algorithm, a value is chosen, since the source of the data is the same thus making the same final choise

23
Q

explain the consensus system failures

A

crash failure: node ceases to send messages

byzantine failure: node send erroneous messages

24
Q

how to solve the byzantine problem

A

By using the two rounds algorithm
in the first round, every node send its plan to all the other nodes
in the second round, every node sends the received data to all the other nodes

25
how to treat crash failure
it can be treated by simply detecting the timeout