Forums Register Login

Is Thread Starvation History?

+Pie Number of slices to send: Send
With modern CPUs, modern operating systems, and modern JVMs, is "thread starvation" a problem only in history? It seems like modern CPUs are preemptive as are operating systems. It seems like good JVMs would use preemption too and so thread starvation might not be a problem anymore. Is that true?

Kaydell
+Pie Number of slices to send: Send
I'm not an expert on the matter, but (e.g.) in Java there's still the concept of "thread priority". Its use is discouraged, but I think lower-priority threads might be starved of CPU cycles on a busy system. But then, probably few systems will be running on 100% for extended periods of time, and low-priority threads can presumably wait a while until they get run; so they may not actually get starved.
+Pie Number of slices to send: Send
For "CPU starvation", all OSes do a great job to make sure that threads of the same priority do get a fair time slice of the processor. This was probably true even before Java -- Java just didn't use it in the early years. In that regard, it is highly unlikely threads of the same priority will starve.

Windows goes even further, to allow threads of different priorities to get a "fair" time slice. (lower priorities run for smaller slices and less often)


As for "lock starvation" (threads being starved because they can't access a synchronization lock), all modern OSes support priority inheritance, to prevent a lower priority thread from starving a higher priority thread.


To answer your question, I am sure someone can come up with a scenario when a thread will starve. There is only so much processing power in a system -- and it should be possible to place such a high demand to exceed it. This is one reason why thread pools are still recommended -- to limit the number of threads in an application.

Henry
+Pie Number of slices to send: Send
Ulf and Henry's answers are good, but I'm not sure they precisely address your question. I think you asked because the early Java literature makes a big deal out of "starvation" because early JVMs used the non-preemptive "Green threads" library. As you suspect, that's not the case anymore, so the general level of urgency of that early literature is no longer warranted.
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 858 times.
Similar Threads
Thread Starvation
Dual processor utilization
64 bit and 32 bit ?
Inturrupting a Thread, Killing a Thread
jtips quiz 3
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 08:04:50.