Câu hỏi phỏng vấn Concurrency
Câu hỏi

Provide some real-liv...

Câu trả lời

Livelock is a concurrency problem where two or more processes or threads continuously change their state in response to each other without making any progress. Here are some real-life examples of livelock:

Example 1: Two People in a Corridor

A classic example of livelock is when two people meet in a narrow corridor and each tries to be polite by moving aside to let the other pass. They end up swaying from side to side without making any progress because they both repeatedly move the same way at the same time[2][9][8].

Example 2: Husband and Wife with a Spoon

In a more illustrative example, imagine a husband and wife trying to eat soup but only have one spoon between them. Each spouse is too polite and will pass the spoon if the other has not yet eaten. As a result, they keep passing the spoon back and forth without either of them eating[10].

Example 3: Processes with Shared Resources

Consider two processes, A and B, that need to access two shared resources, X and Y. Process A holds resource X and needs resource Y, while process B holds resource Y and needs resource X. Both processes use a backoff strategy to avoid deadlock, releasing their held resource and retrying after a random delay. If they happen to choose the same backoff time repeatedly, they will keep retrying and failing to acquire the needed resources, resulting in a livelock[1][6][12].

Example 4: Telephone Call

Another real-world example is when two people try to call each other at the same time and both find the line busy. They both decide to hang up and attempt to call again after the same time interval. This can go on indefinitely, with neither party successfully making the call[11].

Example 5: Traffic on a Narrow Bridge

Imagine two cars approaching a narrow bridge from opposite directions. Both drivers decide to back up to let the other pass, ...

senior

senior

Gợi ý câu hỏi phỏng vấn

junior

Explain the difference between Asynchronous and Parallel programming?

middle

What is a Race Condition?

senior

What are some advantages of Lockless Concurrency?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào