Algorithm Concurrency - Lock Variables Flashcards

1
Q

Lock

A

A shared data item

Processes must acquire such a lock before entering a critical section

Processes have to release a lock when exiting critical section

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

Synonym for the Lock Variables

A

Mutex

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

Syntax

A

process ()
{
acquire lock
critical_section() ;
release lock
remainder_section();
}

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

True vs False Lock

A

True - Critical Section Locked
False - Critical Section Unlocked

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

while(lock == TRUE) {
// wait
}

A

This is a loop that keeps the process waiting (doing nothing) until the lock variable becomes FALSE

this while loop continuously checks the lock condition, as long as the condition is true (meaning the shared resource is being accessed by another process) the loop doesn’t allow the process to move forward.It stays stuck in the loop effectively waiting

once the lock variable is set to false (by the other process releasing the resource) the condition lock == TRUE becomes FALSE

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

Issues with Lock variable

A

As the process continuously evaluates whether a lock has become available

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

Token - Shared variable

A

Usually process ID

Indicated which process is next to enter critical section, set by previous process

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

p0
while(TRUE) {

while(turn !=0) {
//wait
}

critical_section
turn= 1
non critical section

A

turn is a shared variable

turn=0 means P0 has the right to execute the critical section
turn=1 means P1 has the right to execute the critical section

each process alternates between the critical and non-critical section

P0 waits in the loop until turn==0 which means it is P0 to execute the critical section

once the critical section completed the process changes the turn variable to the next number to allow P1 to proceed to the critical section too

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