GoConqr has a new look! Let us know what you think.

Notes

Livelock

Ahmad Abdelwahed Operating Systems 0 English 1 page

Content of the notes (1)

Page 1

In some situations, a process tries to be polite by giving up the locks it already acquired whenever it noticed that it cannot obtain the next lock it needs.

Then waits a millisecond, say, and tries again.

In principle, this is good and should help to detect and avoid deadlock.

However, if the other process does the same thing at exactly the same time, they will be in the situation of two people trying to pass each other on the street when both of them politely step aside, and yet no progress is possible, because they keep stepping the same way at the same time.

void process_A(void) {

acquire_lock(&resource_1);

while (try_lock(&resource_2) == FAIL) {

release_lock(&resource_1);

wait_fixed_time();

acquire_lock(&resource_1);

}

use_both_resources();

release_lock(&resource_2);

release_lock(&resource_1);

}

void process_B(void) {

acquire_lock(&resource_2);

while (try_lock(&resource_1) == FAIL) {

release_lock(&resource_2);

wait_fixed_time();

acquire_lock(&resource_2);

}

use_both_resources();

release_lock(&resource_1);

release_lock(&resource_2);

}

Information

Description
0 Operating Systems (Deadlock) Note on Livelock, created by Ahmad Abdelwahed on 26/06/2015.
Views
4
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?