From the course: Parallel and Concurrent Programming with Java 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Starvation

Starvation - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 1

Start my 1-month free trial

Starvation

- It would be nice if Olivia and I took turns acquiring and releasing the pair of chopsticks so we could each take an equal amount of sushi from the shared plate. But that's not guaranteed to happen. The operating system decides when each of our threads gets scheduled to execute, and depending on the timing of that, it can lead to problems. If Olivia puts down the chopsticks to release her lock on the critical section, but my thread doesn't get a chance to acquire them before she takes them again, then I'll be stuck waiting again, until she takes another piece. If that happens occasionally, it's probably not a big deal. But if it happens regularly. - Too slow. - Then my thread's going to starve. Starvation occurs when a thread is unable to gain access to a necessary resource, and is therefore unable to make progress. If another greedy thread is frequently holding a lock on the shared resource, then the starved thread won't get a chance to execute. - In a simple scenario like ours…

Contents