This one's more directly related to ch13.
Today in 300 (where we're also talking about threads), Dr. Oldham grumbled something to the effect of "If you're dealing with multiple threads, you're going to be looking at some performance gains."* And I seem to remember from my course in Ireland that concurrency can result in more efficient execution overall, even on single-processor machines.** But in what situation would this be the case? I mean, it's obvious that you're going to get more efficient execution if you have multiple processors and the processes that are being dealt with take advantage of this. It's similarly obvious that it is desirable to utilize concurrency for a wide variety of purposes to at least simulate multiple things happening at once (user interfaces, graphical video games, etc.). But how does it make sense that a single processor would be able to complete execution more quickly if it divides its time between multiple tasks?
To use an analogy: I have three different kinds of bread-loaves and a toaster with a single slot. I cut the loaves into slices. Why should it be more efficient to alternate between slices of different types of bread, rather than just proceeding from one loaf to the next in order? Isn't switching between bread-types just extra overhead? (In fact, for many situations, this overhead can get out of hand very quickly if a process uses more threads than there are processors on the machine.)
What's an example of a situation where we could see an improvement in performance thanks to multithreading on a single-processor machine?***
*He actually said nothing that even vaguely resembles this sentence, but it sure sounded like this is what he was getting at.
**It is conceivable that I am misremembering this.
***Please note that, as this page mentions, "the design of concurrent applications is a very complex process that is normally performed by people who make a ton of money, because it takes years of study to figure out how exactly a given task can benefit from concurrent execution." So maybe it's okay if we don't completely understand this just yet.
No comments:
Post a Comment