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

What's the difference betw...

Câu trả lời

Difference Between Deadlock and Livelock

Deadlock and Livelock are both concurrency issues that can occur in multi-threaded or multi-process systems, but they have distinct characteristics and behaviors.

Deadlock

A deadlock is a situation where two or more processes are unable to proceed because each is waiting for the other to release a resource. This results in a complete standstill where none of the processes can make any progress. The key characteristics of a deadlock are:

  • Mutual Exclusion: At least one resource must be held in a non-sharable mode.
  • Hold and Wait: A process holding at least one resource is waiting to acquire additional resources held by other processes.
  • No Preemption: Resources cannot be forcibly taken from processes holding them.
  • Circular Wait: A set of processes are waiting for each other in a circular chain.

For example, consider two processes, A and B. Process A holds resource X and needs resource Y to proceed, while process B holds resource Y and needs resource X. Both processes are waiting indefinitely for the other to release the resource, resulting in a deadlock[1][2][3][4].

Livelock

A livelock is similar to a deadlock in that processes are unable to make progress. However, in a livelock, the processes are not blocked; instead, they continuously change their state in response to each other without making any actual progress. The key characteristics of a livelock are:

  • Processes are actively trying to resolve the conflict but end up in a loop of state changes.
  • No process is able to enter its cr...
senior

senior

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

middle

Explain Deadlock to 5 years old

middle

Is there any difference between a Binary Semaphore and Mutex?

expert

What happens if you have a "race condition" on the lock itself?

Bình luận

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

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