What is starvation?

I wouldn't say that resource starvation is a special case of a livelock. Usually:

  • In a livelock, no thread makes progress but they keep executing. (In a deadlock, they don't even keep executing)

  • When starving, some thread(s) DO make progress and some thread(s) aren't executing.

A good explanation: http://docs.oracle.com/javase/tutorial/essential/concurrency/starvelive.html. But I understand the choice of terminology may vary.

When it comes to starvation, the definition I heard is:

Suppose it is possible to specify an infinite path of execution (interlace) consistent with assumptions (semaphore semantics, OS scheduler behaviour...) such that thread T is suspended waiting for some resource and never resumed, even if it was possible infinitely many times. Then T is called starving.

But the practice doesn't match that. Suppose two threads execute the same critical section in an infinite loop. Your synchronization code allows the first thread to enter the critical section once per hour. Is it starvation? Both threads are allowed to progress, but the first one is doing its work painfully slowly.

The simplest source of starvation are weak semaphores. If you are using a synchronization primitive (or building your own) that behaves similarly, then starvation will result.

Classical problems where starvation is well known:

  • Readers-writers problem. It is possible to synchronize the threads such that (1) the readers will be able to starve the writers (2) the writers will be able to starve the readers (3) no starvation will occur (See http://en.wikipedia.org/wiki/Readers-writers_problem)

  • Dining philosophers (http://en.wikipedia.org/wiki/Dining_philosophers_problem)

For more details, I wholeheartedly recommend The Little Book of Semaphores (free): http://www.greenteapress.com/semaphores/.

You are asking if every starvation is caused by waiting for some resource. I'd say - yes.

A thread can be suspended:

(1) on some blocking system call - waiting on/acquiring a mutex, semaphore, conditional variable; write(), poll() etc.

(2) on some nonblocking operation - like performing computations.

Starving on (1) is starving on resources (mutexes, buffer etc.).

Starving on (2) is starving on CPU - you can regard it as a resource. If it happens, the problem is with scheduler.

HTH


Imagine you're in a queue to purchase food at a restaurant, for which pregnant women have priority. And there's just a whole bunch of pregnant women arriving all the time.

You'll soon be starving. ;)

Now imagine you are a low-priority process and the pregnant women are higher priority ones. =)