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

What is S...

Câu trả lời

Starvation in the context of concurrency refers to a situation where a thread or process is unable to gain regular access to the resources it needs to make progress, despite being ready to run. This typically occurs because other threads or processes are consistently given priority, leading to the affected thread being perpetually denied the necessary resources.

Causes of Starvation

  1. Thread Priority: Higher-priority threads can monopolize CPU time, preventing lower-priority threads from executing[1][2].
  2. Synchronized Blocks: In Java, synchronized blocks do not guarantee the order in which waiting threads will gain access, potentially causing some threads to be blocked indefinitely[1][2].
  3. Infinite Loops: Threads that enter infinite loops without releasing resources can prevent other threads from accessing those resources[1].
  4. Unfair Scheduling Policies: Some operating systems or JVM implementations may have scheduling policies that favor certain threads over others, leading to starvation[1].
  5. Waiting on Objects: The wait() method in Java does not guarantee which waiting thread will be awakened by notify(), potentially causing indefinite waiting for some threads[1][2].
  6. Resource Denial: In database management systems (DBMS), starvation can occur when a transaction is repeatedly denied access to a lock or other resource due to other transactions being prioritized[4][5].

Preventing Starvation

  1. Fair Locks: Use fair locking mechanisms, such as Java’s ReentrantLock with the fairness parameter set to true, to ensure that the longest-waiting thread gains access to resources[1].
  2. Adjust Thread Priorities: Carefully manage thread priorities to avoid over-reliance on them, which can lead to priority inversion and starvation[1].
  3. Timeout Mechanisms: Implement timeout mechanisms when acquiring resources, allowing threads to take alternative actions if a resource cannot be acquired within a specified time[1][5].
  4. **Fair Scheduli...
senior

senior

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

senior

What are some advantages of Lockless Concurrency?

senior

Compare Actor Model with Threading Model for concurrency

junior

What is a Mutex?

Bình luận

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

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