多线程编程和多核编程的区别
本文是The Difference Between Multithreaded and Multicore Programming的读书笔记
- The goal of multithreaded programming is to, instead, keep the idle time of the CPU as low as possible whilst doing the most work possible where the work will be done in serial fashion anyway. If you actually do attempt to do real processing in multiple threads, in most cases your performance will actually degrade faster than if you did it using serial programming. Why? Because the processor takes time to context-switch between tasks, and the more it has to do that, the more overhead you’ll incur.
- On a multicore system, on the other hand, your goals are quite different — you actually do want to spread the work out among the cores so that it DOES executes simultaneously, because your performance gain should be directly related to how many cores you have.
- The common wisdom with some is to run your program in multiple processes, which does work for those situations that doesn’t require a lot of state dependencies or resource sharing. That approach, when it works, is nice, because it scales well with the number of cores you have — and it also scales well in a cluster/cloud computing scenario.
参考资料
The Difference Between Multithreaded and Multicore Programming
分类: 软件设计
