crtical - section problem Flashcards

(18 cards)

1
Q

what does concurrent access to shared data lead to

A

data inconsistency

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

what does maintaining data consist of

A

mechanisms to ensure orderly execution of coperating process

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

Finite buffer shared by producer and consumer , what problems does this lead to

A

Classic Problem: Finite buffer shared by producer and consumer
Producer produces a stream of items and puts them into
buffer
Consumer takes out stream of items
Have to deal with producers waiting for consumers when buffer is
full, and consumers waiting for producers when buffer is empty

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

write code for producer in buffer

A

while (true) {
/* produce an item and put in nextProduced */
while (count == BUFFER_SIZE); // wait if buffer full
buffer [in] = nextProduced; // store new item
in = (in + 1) % BUFFER_SIZE; // increment IN pointer.
count++; // Increment counter
}

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

write code for consumer in buffer

A

while (true) {
while (count == 0) ; // do nothing
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
count–;
/* consume the item in nextConsumed */
}

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

how can count++ be compile as

A

could be compiled as a sequence of CPU
instructions
register1 = count
register1 = register1 + 1
count = register1

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

what else can count– be compiled as

A

could be compiled as a sequence of CPU
instructions:
register2 = count
register2 = register2 - 1
count = register2

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

what problem could occur when count++ and count– (producer and consumer) are executed at the same time

A

race condition

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

what is the solution criteria to critical section problem

A

Solution to protect against concurrent modification of data in the critical section with the following criteri
mutual exclusion
progress
bounded waiting

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

what is mutual exclusion

A

if process Pi is in its critical section
(i.e. where shared variables could be altered inconsistently),
then no other processes can be in this critical section

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

what is progress

A

no process outside of the critical section (i.e. in the
remainder section) should block a process waiting to enter.

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

what is bounded waiting

A

Bounded Waiting - A bound must exist on the number of
times that other processes are allowed to enter the critical
section after a process has made a request to enter its critical
section and before that request is granted (i.e. it must be fair,
so one poor process is not always waiting behind the others

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

what are the assumptions to the solution Criteria to Critical-Section Problem

A

Assume that each process executes at a nonzero speed.
No assumption concerning relative speed of the N processes

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

what is the peterson’s solution

A

Two process solution.
Assume that the CPU’s register LOAD and STORE
instructions are atomic (not realistic on modern CPUs,
educational example).
The two processes share two variables:
int turn;
Boolean wants in[2];
The variable turn indicates whose turn it is to enter the
critical section.
The wants in array is used to indicate if a process is ready to
enter the critical section. wants in[i] = true implies that
process Pi is ready

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

what does the variable turn show in peterson’s solution

A

The variable turn indicates whose turn it is to enter the
critical section

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

variable wants_in in peterson’s solution

A

The wants in array is used to indicate if a process is ready to
enter the critical section. wants in[i] = true implies that
process Pi is ready

16
Q

peterson’s algorithm for process P_I

A

do {
wants_in[i] = TRUE; // I want access…
turn = j; // but, please, you go first
while (wants_in[j] && turn == j); // if you are waiting and it is
// your turn, I will wait.
[critical section]
wants_in[i] = FALSE; // I no longer want access.
[remainder section]
} while (TRUE);

17
Q

how does the peterson algorithm acheive fairness

A

When both processes are interested, they achieve fairness through
the turn variable, which causes their access to alternate