• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is Thread Starvation History?

 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic