Ok, so I’ve tagged this question with java because I’m primarily thinking about it as that is the language I’m writing it currently. However, this is equally as general in the programming world.
My question is: is there any limit to how many threads a processor can handle, and more over what is the likelihood of my application maxing this limit? AND what would happen if I did?
I don’t really know much about threads – I just know that they enable you to execute two processes at once (that’s probably not even the correct term). Initially, I thought single core processors didn’t allow for multiple threads but then common sense kicked in and I thought about how that couldn’t be possible given Windows and things. But now I’m wondering, what is the difference between single core and multi core processors / what do multi core processors allow?
Explanations in the simplest terms possible would be much appreciated. Thanks in advance
A processor can normally run one thread at a time. It can handle far more than that, however. When you have several processes running, your processor(s) switches between them very quickly, giving each one a slice of the processor’s time. This gives an illusion of concurrency, but really everything is happening in serial.
There is not really a hard limit on the number of threads you can run, but there is overhead involved when the processor switches between threads. If you’re building an application with a GUI, it’s a good idea to spawn a separate thread for long-running tasks so that the GUI can stay responsive. If you expect to run on a computer with multiple processors or some other solution which allows true concurrency, you can try to take advantage of that by running in separate threads, but it does make your problem more complex and can cause bugs which are hard to track down.
Most computers are multi-core today and can actually run several threads concurrently. In fact more concurrency, rather than stronger individual processors, is likely how computers will develop in the future. Being able to take advantage of that is important, but it’s hard. If you don’t have a specific reason to make your application multithreaded, I recommend avoiding it until you feel comfortable doing so.