Questions tagged [critical-section]
21 questions
7
votes
3 answers
Bounded waiting and starvation free in critical section problem
I have 4 questions regarding relation between starvation and bounded waiting.
1.Does starvation-freedom imply deadlock-freedom?
My Answer:
From here,
definition of starvation free is
Freedom from Starvation -:Every thread that attempts to acquire…
laura
- 337
- 1
- 3
- 12
7
votes
2 answers
Understanding N process Peterson's algorithm
The intuitive informal description of two process Peterson's algorithm for process 0 can be given as follows:
flag[0]=true; //I am ready to enter my critical region
turn=1; //but you may take your turn to…
Mahesha999
- 1,773
- 7
- 30
- 45
3
votes
2 answers
What is the problem with this Busy Wait solution for two threads?
We have two processes. One process produces F and the other process consumes F
Initialization:
Consuming = false
Produced = false
F = EMPTY
The first thread (we can think of it as some kind of producer):
P1:
loop_for_ever:
Produce(F)
…
jrook
- 133
- 1
- 7
3
votes
2 answers
Increment and Decrement on binary semaphores when their values are $1$ and $0$ respectively?
What happens if we increment binary semaphore $x$ when it is equal to $1$.
E.g A process executes $V(x)$ when $x==1$;
What are the possible cases then-
Process would be blocked till $x$ becomes $0$. The moment $x$ becomes $0$,it is incremented.…
Mr. Sigma.
- 1,301
- 1
- 16
- 38
3
votes
2 answers
Race condition, my doubt on Peterson's algorithm vs. C
I have seen this C code showing an implentation of Peterson's Critical Section algorithm. It is obviously skeletal and hardwired for two threads but the logic is supposed to be correct in detail.
Despite reading and talking I remain with a grain of…
pitosalas
- 133
- 3
3
votes
0 answers
Why is the Black-White Bakery Algorithm considered bounded?
As stated in Lamport's papers for the bakery algorithm he states that the ticket numbers are unbounded specifically
The range of values of number is unbounded.
and
Fortunately, practical considerations will place an
upper bound on the value of…
MarkovsConundrum
- 31
- 2
3
votes
4 answers
Whats exact definition of 'atomicity' in programming?
the definition of 'atomicity' says that a transaction should be able to be terminated without being touched or manipulated by possibly concurrent running actions during its process. But does that also mean that a program should not run concurrent…
JinseiNagai
- 131
- 1
- 2
2
votes
1 answer
Peterson's Algorithm | Context switch after turn=process
Suppose we have two processes P0 and P1 using Peterson's Algorithm to access a critical section.
Process P0 starts executing and sets its interested to TRUE and turn is set to 0. A context switch happens right after and process P1 starts executing.…
tomac231
- 21
- 1
2
votes
0 answers
Is a single starved process considered deadlocked?
In regard to the critical section problem, an algorithm that switches between allowing one of two processes, P1 or P2, to complete their critical section would cause starvation for P1 if P2 stayed in its non-critical section forever.
However, if P2…
Adriankusiak
- 21
- 2
2
votes
1 answer
For what example would Maekawa's algorithm allow out of timestamp order access to the critical section
For what example would Maekawa's algorithm allow out of timestamp order access to the critical section. It is mentioned that ordering is not satisfied in Maekawa's algorithm. But in what scenario would this be true?
From my understanding, we will…
sd22gg44
- 21
- 1
2
votes
1 answer
Deadlock vs "Progress" requirement of the solution to the critical section problem
I came across following problem:
Consider following code:
()
{
[] = ;
([]);
/* */
[] = ;
/* */
}
Let flag is declared as Boolean flag[2] and Pi denote one process while Pj denotes other process and i=1-j. Both…
RajS
- 1,737
- 5
- 28
- 50
1
vote
0 answers
Does the following piece of code lead to a deadlock?
Process X
/* other code for process x*/
while (true) {
1) varP = true;
2) while (varQ == true)
{
/* Critical Section */
3) varP = false;
}
}
/* other code for process X */
Process Y
/* other code for process Y…
Krish__
- 23
- 5
1
vote
1 answer
Bounded waiting and progress requirements of critical section problem solution based on exchange instruction
Atomic exchange instruction is given as follows:
void exchange (int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;
}
Now consider the solution to critical section problem based on above instruction:
1 int const n = /* number…
Mahesha999
- 1,773
- 7
- 30
- 45
1
vote
0 answers
Order of releasing the semaphores
I was studying the dining philosopher problem (See problem description) and its solution using semaphores, and I came across this :
**Code for the ith philosopher:**
while(1)
{
take_chopstick[i];
take_chopstick[ (i+1) % 5] ;
…
Girik Garg
- 11
- 2
1
vote
0 answers
Dekker's Algorithm spin on intent instead of turn
For Dekker's algorithm given below (from Wikipedia), why is it that we wait for the turn to change, instead of waiting for p1 to set it's flag to false? It seems to me that it would be safer (or more efficient?) to wait for p1 to complete its exit…
Chien
- 11
- 2